Sub SelectGroupReport()
Dim wksReport As Worksheet
Dim rngStart As Range
Dim iStartCol As Integer
Dim iStartRow As Integer
Dim iEndCol As Integer
Dim iEndRow As Integer
Dim rngGroupReport As Range
Dim iReportCount As Integer
Dim iReportNumber As Integer
Set wksReport = ThisWorkbook.Sheets("Sheet1")
'rngStart is going to be the top-left cell in the subreport.
'I'm assuming that this will always being in A2.
Set rngStart = Range("A2")
'The subreport range starts in column 1 (A)...
iStartCol = 1
'..and ends in column 18 (R)
iEndCol = 18
'Determine how many subreports will be needed by counting
'non-blank cells in column A
iReportCount = Application.WorksheetFunction.CountA(wksReport.Range("A:A"))
'Main loop to go through each subreport
For iReportNumber = 1 To iReportCount
'Get the row number that will be the top(start) of the required subreport range
iStartRow = rngStart.Row
'Now determine the bottom(end) of the required subreport range
If iReportNumber = iReportCount Then
'For the last report - End(xlDown) will go all the way to
'row 65536, so we look for the end of row B by using the offset
iEndRow = rngStart.Offset(0, 1).End(xlDown).Row
ElseIf rngStart.Offset(1, 0).Value = "" Then
'For cases where we have more that one row we use
'End(xlDown) to determin the position of the next header
'and set our ending row to the row above that.
iEndRow = rngStart.End(xlDown).Offset(-1, 0).Row
Else
'when the cell below our starting cell is populated
'the report should only have a single row
'so we set the end row to be the same as the start row
iEndRow = iStartRow
End If
'We can now set the sub report range
With wksReport
Set rngGroupReport = .Range(.Cells(iStartRow, iStartCol), .Cells(iEndRow, iEndCol))
End With
'insert your code here to handle each report
'the following is just to prove that the code is working
rngGroupReport.Select
MsgBox "Report " & CStr(iReportNumber)
'Move to the next report
'using the same logic as above
If rngStart.Offset(1, 0).Value = "" Then
Set rngStart = rngStart.End(xlDown)
Else
Set rngStart = rngStart.Offset(1, 0)
End If
Next iReportNumber
'Clear object variables
Set rngGroupReport = Nothing
Set wksReport = Nothing
End Sub