Advertisement

06.26.2008 at 03:47PM PDT, ID: 23520109
[x]
Attachment Details

VBA loop to find cell w/ match, get that row and next 8 rows, and delete block

Asked by b0lsc0tt in Microsoft Excel Spreadsheet Software, VB Script

Tags: Excel 2007, VBA, VBScript

This isn't my expertise.  I do know VB to a certain extent but not in relation to MS Office Apps.  Trying to use VB in Excel to get rid of some blocks of rows.  My sheet has 13K+ of data but every 40 or so there is a block of 9 rows I want to remove.  The first row always starts with the text I use in the Find line (see snippet).  I want to find the match and then call another Sub that will use that row, get the next 8 and delete the block.  This should then loop through the sheet to get rid of all matches.

This seems to be working but just once.  After the first row is deleted I get an error in the VB Editor.  The error is:

Run-time error 1004
Application-defined or object-defined error

The Help explanation was not helpful enough.  I am not use to using the VB Editor either so maybe I am overlooking some great tool or help there.

BTW, I just added the Option Explicit and am trying to make sure I properly declare variables.  It wasn't there when I got the error so feel free to let me know if I need to add another declaration or two.

Feel free to correct me if I use an incorrect term.  I can provide more details if needed.  I know Excel pretty well but just haven't ever made a VBA.  I have tried to avoid them like the plague but am actually excited about this project.  There will actually be more steps to it too (which I may need help with).  I am not new to programming or EE but appreciate your patience and help with this, especially if it comes with instruction and helps me learn this.  I am not looking for someone to just do the work. ;)

Thanks!

bolStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
Option Explicit
Public Sub DeleteExtra()
    Dim c As Range
    With Worksheets("Sheet2").Cells
        Set c = .Find(What:="CSALLRMSCHD*", LookAt:=xlPart, After:=ActiveCell, LookIn:=xlFormulas, SearchDirection:=xlNext)
        If Not c Is Nothing Then
            Do
                i = c.Row
                Call DeleteBlock(i)
                Set c = .FindNext(c)
            Loop While Not c Is Nothing
        End If
    End With
End Sub
 
 
Private Sub DeleteBlock(i)
    Dim myUnion As Range
    Set myUnion = Union(Rows(i), Rows(i + 1), Rows(i + 2), Rows(i + 3), Rows(i + 4), Rows(i + 5), Rows(i + 6), Rows(i + 7), Rows(i + 8))
    myUnion.EntireRow.Delete
End Sub
 
 
[+][-]06.26.2008 at 03:54PM PDT, ID: 21879752

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 03:56PM PDT, ID: 21879757

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Excel Spreadsheet Software, VB Script
Tags: Excel 2007, VBA, VBScript
Sign Up Now!
Solution Provided By: nutsch
Participating Experts: 1
Solution Grade: A
 
 
[+][-]06.26.2008 at 04:04PM PDT, ID: 21879792

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 04:05PM PDT, ID: 21879797

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 04:09PM PDT, ID: 21879814

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 04:10PM PDT, ID: 21879818

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 04:12PM PDT, ID: 21879825

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 04:26PM PDT, ID: 21879876

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 04:31PM PDT, ID: 21879893

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 04:36PM PDT, ID: 21879910

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 04:39PM PDT, ID: 21879933

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 04:41PM PDT, ID: 21879943

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 04:42PM PDT, ID: 21879946

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 04:43PM PDT, ID: 21879957

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 04:45PM PDT, ID: 21879964

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 04:53PM PDT, ID: 21879998

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.26.2008 at 05:03PM PDT, ID: 21880045

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_EXPERT_20070906