Next blank row moving down through a data set

Westbury

Board Regular
Joined
Jun 7, 2009
Messages
149
I have a table of data which is broken up by a number of blank rows at irregular spacing. I need to find the row number of the next blank row after the last occurance of a string in col A---which can be somewhere in the middle of the data table. I've got the row number of the last occurence of FRED, as an example, below but am stuck finding the next blank row. FRED is effectively a heading with rows of other data below his name followed by a blank row.

Code:
Sub find_occurance_of_string()


    Dim FirstRow As Long
    Dim LastRow As Long
    Dim erow As Long
    
With Sheets("DATA")
    FirstRowPFW = Range("A:A").Find(what:="FRED", after:=Range("A1")).Row
    LastRowPFW = Range("A:A").Find(what:="FRED", after:=Range("A1"), searchdirection:=xlPrevious).Row
       
End With


    MsgBox FirstRow & vbCrLf & LastRow
    
    'empty row after last row containing  FRED in col A
    
   erow = Sheets("DATA").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
   
   MsgBox erow   
      
End Sub

Would be grateful for a steer in the right direction.
thanks
Geoff
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
How about
Code:
Sub find_occurance_of_string()
    Dim FirstRow As Range
    Dim erow As Long
    
    With Sheets("DATA")
        Set FirstRow = .Range("A:A").Find("FRED", , , xlPart, , , False, , False)
        erow = FirstRow.End(xlDown).Offset(1).Row
    End With

    MsgBox FirstRow.Row & vbCrLf & erow
End Sub
 
Upvote 0
My description wasn't totally accurate----sorry!. There are several instances of "FRED"; I need to find the last one and then the subsequent blank row.
 
Upvote 0
Ok, how about
Code:
Sub find_occurance_of_string()
    Dim LastRow As Range
    Dim erow As Long
    
    With Sheets("DATA")
        Set LastRow = .Range("A:A").Find("FRED", , , xlPart, xlByRows, xlPrevious, False, , False)
        erow = LastRow.End(xlDown).Offset(1).Row
    End With

    MsgBox LastRow.Row & vbCrLf & erow
End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,191
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top