Hi everyone,
I'm just starting up with VBA to get rid of some manual work I have to usually do.
I have to group certain rows in sheets, in this case it would be anything between ranges 1 and 2, 2 and 3, 3 and 4 for each sheet. "Total Revenues Post RMC" and so on are constant for every sheet, so I'm trying to figure out how to do it for one and then just use "For" for the rest of them. I came up with something like this below
I think the Set Range lines don't return range but the value of cell for some reason.. I would appreciate any help
I'm just starting up with VBA to get rid of some manual work I have to usually do.
I have to group certain rows in sheets, in this case it would be anything between ranges 1 and 2, 2 and 3, 3 and 4 for each sheet. "Total Revenues Post RMC" and so on are constant for every sheet, so I'm trying to figure out how to do it for one and then just use "For" for the rest of them. I came up with something like this below
Code:
Sub Grouping_Rows()
Dim Range1 As Range
Dim Range2 As Range
Dim Range3 As Range
Dim Range4 As Range
For x = 2 To Sheets.Count
Set Range1 = Range("D:D").Find("Total Revenues Post RMC", After:=Range("D9"), MatchCase:=True)
Set Range2 = Range("D:D").Find("Sector Direct Costs", After:=Range("D9"), MatchCase:=True)
Set Range3 = Range("D:D").Find("Country Direct Costs", After:=Range("D9"), MatchCase:=True)
Set Range4 = Range("D:D").Find("Product Direct Costs", After:=Range("D9"), MatchCase:=True)
ActiveSheet.Range(Range1 + 1, Range2 - 1).Select.Rows.Group
Next
End Sub
I think the Set Range lines don't return range but the value of cell for some reason.. I would appreciate any help