View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
mp mp is offline
external usenet poster
 
Posts: 70
Default easiest way to find next non blank row

On 4/16/2012 10:38 PM, GS wrote:
I suggest a different approach...

1. I need to know which row/column the data starts.

2. I need to find the last row containing data.

3. I need to get the first block of data to the last block of data.

4. I need to process each block in turn.

5. I need to end the procedure on the last row of the last block.


Example code for a set of data starting in Row1/Col1:

Sub GetDataBlocks()
Dim lLastRow&, lLastCol&, lStartRow&, lStartCol&, r1&, r2& 'as long
Dim sBlocks$ 'as string
Dim v As Variant

'The first/last row of data
lStartRow = 1: lStartCol = 1 'edit to suit
lLastRow = Cells(Rows.Count, lStartCol).End(xlUp).Row

'Get the blocks of data
'The 1st block
r1 = lStartRow
r2 = Cells(r1, lStartCol).End(xlDown).Row
sBlocks = r1 & ":" & r2
'The remaining blocks
Do Until r2 = lLastRow
r1 = Cells(r2, lStartCol).End(xlDown).Row
r2 = Cells(r1, lStartCol).End(xlDown).Row
sBlocks = sBlocks & "," & r1 & ":" & r2
Loop

'Process the blocks
For Each v In Split(sBlocks, ",")
Debug.Print Rows(v).Address
Next 'v
End Sub

Garry,
That is wayyyy cool. Thank you so much.
Mark