Exclude Certain Rows from Auto Grouping Macro

Viewed 21

I currently have a macro that groups my different product brand by name. Example, product brand 1 is grouped together, product brand 2 is grouped together etc. etc. For each region in my spreadsheet I have a subtotal row. This row sums the totals of each product brand. My macro is treating this subtotal as another brand but I want it to ignore this row in the auto grouping. Any ideas how to do that?

Here is my current macro:

Sub GroupBrands()

Dim myValue As Variant

Dim myCol As String

Dim myRow As Long

Dim startRow As Long

Dim lastRow As Long

'Which column to look at?

myCol = "A"

'Which row to look at first?

myRow = 4

lastRow = Cells(myRow, myCol).End(xlDown).Row

myValue = Cells(myRow, myCol)

startRow = myRow

Application.ScreenUpdating = False

For i = myRow + 1 To lastRow + 1

  If Cells(i, myCol).Value <> myValue Then

  'New group begins

  Range(startRow & ":" & i - 2).EntireRow.Group

  startRow = i

  myValue = Cells(i, myCol).Value


  End If

  If myValue = "" Then

  'blank cell

  Exit For

  End If

Next i

Application.ScreenUpdating = True

End Sub
0 Answers
Related