Pritchard and folks:
Another tactic:
FirstRow = Columns("B:B").Find(What:="~* ", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlPrevious, MatchCase:=False, SearchFormat:=False).Offset(1, 0).Row
Each subtotal begins with an asterix and more than 3 blank spaces before the cost center number (like "* ").
That means, since the LastRow is the first find of "555ROAR7777" from B1 down,
then the FirstRow the row below the next line above the LastRow that begins with "* ".
This also happens to be the next ungrouped, visible line when the grouped rows are collapsed.
Use tilda, right? Maybe I can do a search up? Like:
FirstRow = ws.Range("B:B").Find(What:="~* ", After:=ws.Range("B" & LastRow) LookIn:=xlFormulas _
, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlUp, _
MatchCase:=False, SearchFormat:=False).Row
Would this work? How do I make the SearchDirection go up? How do I refer to a specific cell in the After: section?
Also, I tried this as a stand alone macro and it didn't work:
Sub trywhynot()
Dim LastRow As Long
Dim FirstRow As Long
Range("B1").Select
LastRow = Application.WorksheetFunction.Match("*555ROAR7777*", Range("B:B"), 0)
FirstRow = Range("B" & LastRow).Offset(-1, 0).Select
MsgBox LastRow 'Got the correct row #350 (let's say)
MsgBox FirstRow 'Got "-1" which clearly is not a row number
End Sub
Also, using a simple Macro to test, this worked for the next subtotal after my found value:
NextRow = Columns("B:B").Find(What:="~* ", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Row
But when I change SearchDirection:= xlNext to SearchDirection:= xlUp it still goes to the next lower row find.
This didn't work either:
NextRow = Columns("B:B").Find(What:="~* ", Before:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Row
I found it, It Works: xlPrevious
NextRow = Columns("B:B").Find(What:="~* ", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlPrevious, MatchCase:=False, SearchFormat:=False).Offset(1, 0).Row
Thank you - Rowland