PC Review


Reply
Thread Tools Rate Thread

code to delete null rows after criteria found

 
 
tbmarlie
Guest
Posts: n/a
 
      10th Oct 2007
I'm trying to create some vba code to delete any rows that match a
specific criteria plus any null rows below that row. See below for
some sample data:

column f column g
xxx-xx-xxx SOLTAX EARNINGS NO 1
SOLTAX EARNINGS NO 2
GROUP TOTALS SOLTAX EARNINGS NO 1
SOLTAX EARNINGS NO 2
xxx-xx-xxx INCENTIVE PAYMENTS YTD
EXCLUDED FROM FICA-HI YTD


So, I would want to delete any row with the criteria, "GROUP TOTALS"
in column f plus any row(s) below the GROUP TOTALS row that has a
null
in column f. It would do this until it reached the bottom of the
overall data. In this example, there would be 2 rows that need to be
deleted - The GROUP TOTALS row and the row immediately below it, but
there could be a variable number of blank rows below the GROUP TOTALS
row. Thanks

 
Reply With Quote
 
 
 
 
Zone
Guest
Posts: n/a
 
      11th Oct 2007
tbmarlie,
This is a fairly simple operation except what to do at the bottom of the
data. If care isn't taken, the code could easily just go into an endless
loop deleting blank rows after the bottom of the data. If row 1 is a
heading row and the data starts at row 2, and IF there are no gaps (empty
cells) in column G, and IF there is at least one empty row after the data,
this should work for you. James

Sub Out()
Dim k As Long
For k = Cells(2, "g").End(xlDown).Row To 2 Step -1
If Cells(k, "f") = "GROUP TOTALS" Then
While Cells(k + 1, "f") = "" And Cells(k + 1, "g") <> ""
Rows(k + 1).EntireRow.Delete
Wend
Rows(k).EntireRow.Delete
End If
Next k
End Sub

"tbmarlie" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm trying to create some vba code to delete any rows that match a
> specific criteria plus any null rows below that row. See below for
> some sample data:
>
> column f column g
> xxx-xx-xxx SOLTAX EARNINGS NO 1
> SOLTAX EARNINGS NO 2
> GROUP TOTALS SOLTAX EARNINGS NO 1
> SOLTAX EARNINGS NO 2
> xxx-xx-xxx INCENTIVE PAYMENTS YTD
> EXCLUDED FROM FICA-HI YTD
>
>
> So, I would want to delete any row with the criteria, "GROUP TOTALS"
> in column f plus any row(s) below the GROUP TOTALS row that has a
> null
> in column f. It would do this until it reached the bottom of the
> overall data. In this example, there would be 2 rows that need to be
> deleted - The GROUP TOTALS row and the row immediately below it, but
> there could be a variable number of blank rows below the GROUP TOTALS
> row. Thanks
>



 
Reply With Quote
 
tbmarlie
Guest
Posts: n/a
 
      11th Oct 2007
On Oct 11, 3:51 am, "Zone" <KingOfWhi...@aol.com> wrote:
> tbmarlie,
> This is a fairly simple operation except what to do at the bottom of the
> data. If care isn't taken, the code could easily just go into an endless
> loop deleting blank rows after the bottom of the data. If row 1 is a
> heading row and the data starts at row 2, and IF there are no gaps (empty
> cells) in column G, and IF there is at least one empty row after the data,
> this should work for you. James
>
> Sub Out()
> Dim k As Long
> For k = Cells(2, "g").End(xlDown).Row To 2 Step -1
> If Cells(k, "f") = "GROUP TOTALS" Then
> While Cells(k + 1, "f") = "" And Cells(k + 1, "g") <> ""
> Rows(k + 1).EntireRow.Delete
> Wend
> Rows(k).EntireRow.Delete
> End If
> Next k
> End Sub
>
> "tbmarlie" <tbmar...@yahoo.com> wrote in message
>
> news:(E-Mail Removed)...
>
>
>
> > I'm trying to create some vba code to delete any rows that match a
> > specific criteria plus any null rows below that row. See below for
> > some sample data:

>
> > column f column g
> > xxx-xx-xxx SOLTAX EARNINGS NO 1
> > SOLTAX EARNINGS NO 2
> > GROUP TOTALS SOLTAX EARNINGS NO 1
> > SOLTAX EARNINGS NO 2
> > xxx-xx-xxx INCENTIVE PAYMENTS YTD
> > EXCLUDED FROM FICA-HI YTD

>
> > So, I would want to delete any row with the criteria, "GROUP TOTALS"
> > in column f plus any row(s) below the GROUP TOTALS row that has a
> > null
> > in column f. It would do this until it reached the bottom of the
> > overall data. In this example, there would be 2 rows that need to be
> > deleted - The GROUP TOTALS row and the row immediately below it, but
> > there could be a variable number of blank rows below the GROUP TOTALS
> > row. Thanks- Hide quoted text -

>
> - Show quoted text -


Worked great except that it also deleted the header row.

 
Reply With Quote
 
Zone
Guest
Posts: n/a
 
      11th Oct 2007
I don't see how that could happen, since it only goes up to row 2. You mean
it deleted row 1?

"tbmarlie" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Oct 11, 3:51 am, "Zone" <KingOfWhi...@aol.com> wrote:
>> tbmarlie,
>> This is a fairly simple operation except what to do at the bottom of
>> the
>> data. If care isn't taken, the code could easily just go into an endless
>> loop deleting blank rows after the bottom of the data. If row 1 is a
>> heading row and the data starts at row 2, and IF there are no gaps (empty
>> cells) in column G, and IF there is at least one empty row after the
>> data,
>> this should work for you. James
>>
>> Sub Out()
>> Dim k As Long
>> For k = Cells(2, "g").End(xlDown).Row To 2 Step -1
>> If Cells(k, "f") = "GROUP TOTALS" Then
>> While Cells(k + 1, "f") = "" And Cells(k + 1, "g") <> ""
>> Rows(k + 1).EntireRow.Delete
>> Wend
>> Rows(k).EntireRow.Delete
>> End If
>> Next k
>> End Sub
>>
>> "tbmarlie" <tbmar...@yahoo.com> wrote in message
>>
>> news:(E-Mail Removed)...
>>
>>
>>
>> > I'm trying to create some vba code to delete any rows that match a
>> > specific criteria plus any null rows below that row. See below for
>> > some sample data:

>>
>> > column f column g
>> > xxx-xx-xxx SOLTAX EARNINGS NO 1
>> > SOLTAX EARNINGS NO 2
>> > GROUP TOTALS SOLTAX EARNINGS NO 1
>> > SOLTAX EARNINGS NO 2
>> > xxx-xx-xxx INCENTIVE PAYMENTS YTD
>> > EXCLUDED FROM FICA-HI YTD

>>
>> > So, I would want to delete any row with the criteria, "GROUP TOTALS"
>> > in column f plus any row(s) below the GROUP TOTALS row that has a
>> > null
>> > in column f. It would do this until it reached the bottom of the
>> > overall data. In this example, there would be 2 rows that need to be
>> > deleted - The GROUP TOTALS row and the row immediately below it, but
>> > there could be a variable number of blank rows below the GROUP TOTALS
>> > row. Thanks- Hide quoted text -

>>
>> - Show quoted text -

>
> Worked great except that it also deleted the header row.
>



 
Reply With Quote
 
tbmarlie
Guest
Posts: n/a
 
      11th Oct 2007
On Oct 11, 10:37 am, "Zone" <KingOfWhi...@aol.com> wrote:
> I don't see how that could happen, since it only goes up to row 2. You mean
> it deleted row 1?
>
> "tbmarlie" <tbmar...@yahoo.com> wrote in message
>
> news:(E-Mail Removed)...
>
>
>
> > On Oct 11, 3:51 am, "Zone" <KingOfWhi...@aol.com> wrote:
> >> tbmarlie,
> >> This is a fairly simple operation except what to do at the bottom of
> >> the
> >> data. If care isn't taken, the code could easily just go into an endless
> >> loop deleting blankrowsafterthe bottom of the data. If row 1 is a
> >> heading row and the data starts at row 2, and IF there are no gaps (empty
> >> cells) in column G, and IF there is at least one empty rowafterthe
> >> data,
> >> this should work for you. James

>
> >> Sub Out()
> >> Dim k As Long
> >> For k = Cells(2, "g").End(xlDown).Row To 2 Step -1
> >> If Cells(k, "f") = "GROUP TOTALS" Then
> >> While Cells(k + 1, "f") = "" And Cells(k + 1, "g") <> ""
> >> Rows(k + 1).EntireRow.Delete
> >> Wend
> >> Rows(k).EntireRow.Delete
> >> End If
> >> Next k
> >> End Sub

>
> >> "tbmarlie" <tbmar...@yahoo.com> wrote in message

>
> >>news:(E-Mail Removed)...

>
> >> > I'm trying to create some vba code todeleteanyrowsthat match a
> >> > specificcriteriaplus anynullrowsbelow that row. See below for
> >> > some sample data:

>
> >> > column f column g
> >> > xxx-xx-xxx SOLTAX EARNINGS NO 1
> >> > SOLTAX EARNINGS NO 2
> >> > GROUP TOTALS SOLTAX EARNINGS NO 1
> >> > SOLTAX EARNINGS NO 2
> >> > xxx-xx-xxx INCENTIVE PAYMENTS YTD
> >> > EXCLUDED FROM FICA-HI YTD

>
> >> > So, I would want todeleteany row with thecriteria, "GROUP TOTALS"
> >> > in column f plus any row(s) below the GROUP TOTALS row that has a
> >> >null
> >> > in column f. It would do this until it reached the bottom of the
> >> > overall data. In this example, there would be 2rowsthat need to be
> >> > deleted - The GROUP TOTALS row and the row immediately below it, but
> >> > there could be a variable number of blankrowsbelow the GROUP TOTALS
> >> > row. Thanks- Hide quoted text -

>
> >> - Show quoted text -

>
> > Worked great except that it also deleted the header row.- Hide quoted text -

>
> - Show quoted text -


My mistake - it worked perfect. There was some other code that I had
in my macro that was deleting the first row. Thanks again.

 
Reply With Quote
 
Zone
Guest
Posts: n/a
 
      11th Oct 2007
You're welcome. Glad you got it straightened out. James

"tbmarlie" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Oct 11, 10:37 am, "Zone" <KingOfWhi...@aol.com> wrote:
>> I don't see how that could happen, since it only goes up to row 2. You
>> mean
>> it deleted row 1?
>>
>> "tbmarlie" <tbmar...@yahoo.com> wrote in message
>>
>> news:(E-Mail Removed)...
>>
>>
>>
>> > On Oct 11, 3:51 am, "Zone" <KingOfWhi...@aol.com> wrote:
>> >> tbmarlie,
>> >> This is a fairly simple operation except what to do at the bottom
>> >> of
>> >> the
>> >> data. If care isn't taken, the code could easily just go into an
>> >> endless
>> >> loop deleting blankrowsafterthe bottom of the data. If row 1 is a
>> >> heading row and the data starts at row 2, and IF there are no gaps
>> >> (empty
>> >> cells) in column G, and IF there is at least one empty rowafterthe
>> >> data,
>> >> this should work for you. James

>>
>> >> Sub Out()
>> >> Dim k As Long
>> >> For k = Cells(2, "g").End(xlDown).Row To 2 Step -1
>> >> If Cells(k, "f") = "GROUP TOTALS" Then
>> >> While Cells(k + 1, "f") = "" And Cells(k + 1, "g") <> ""
>> >> Rows(k + 1).EntireRow.Delete
>> >> Wend
>> >> Rows(k).EntireRow.Delete
>> >> End If
>> >> Next k
>> >> End Sub

>>
>> >> "tbmarlie" <tbmar...@yahoo.com> wrote in message

>>
>> >>news:(E-Mail Removed)...

>>
>> >> > I'm trying to create some vba code todeleteanyrowsthat match a
>> >> > specificcriteriaplus anynullrowsbelow that row. See below for
>> >> > some sample data:

>>
>> >> > column f column g
>> >> > xxx-xx-xxx SOLTAX EARNINGS NO 1
>> >> > SOLTAX EARNINGS NO 2
>> >> > GROUP TOTALS SOLTAX EARNINGS NO 1
>> >> > SOLTAX EARNINGS NO 2
>> >> > xxx-xx-xxx INCENTIVE PAYMENTS YTD
>> >> > EXCLUDED FROM FICA-HI YTD

>>
>> >> > So, I would want todeleteany row with thecriteria, "GROUP TOTALS"
>> >> > in column f plus any row(s) below the GROUP TOTALS row that has a
>> >> >null
>> >> > in column f. It would do this until it reached the bottom of the
>> >> > overall data. In this example, there would be 2rowsthat need to be
>> >> > deleted - The GROUP TOTALS row and the row immediately below it, but
>> >> > there could be a variable number of blankrowsbelow the GROUP TOTALS
>> >> > row. Thanks- Hide quoted text -

>>
>> >> - Show quoted text -

>>
>> > Worked great except that it also deleted the header row.- Hide quoted
>> > text -

>>
>> - Show quoted text -

>
> My mistake - it worked perfect. There was some other code that I had
> in my macro that was deleting the first row. Thanks again.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hpw do I delete multiple empty rows found between filled rows? Bill Microsoft Excel Worksheet Functions 1 15th Nov 2009 12:52 AM
Delete Null/Blank Rows Theresa Microsoft Excel Misc 8 18th Dec 2007 05:17 AM
vba code to delete null rows after criteria found tbmarlie Microsoft Excel Programming 1 11th Oct 2007 02:17 PM
Code help, delete rows based on column criteria =?Utf-8?B?U3RvdXQ=?= Microsoft Excel Misc 2 20th Mar 2007 01:17 PM
Re: Further help on delete criteria found rjamison Microsoft Excel Programming 0 14th Jun 2005 12:14 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:56 PM.