I need a macro to group rows based on values in a specific column.
I have a dashboard with data from row 21 to row 5000. The cells in column GM have the following values: "Hide", "Not Hide", or are blank. The data is sorted based on values in columns A, B, and C. As a result, there is no inherent order to the "Hide" or "Not Hide" values in the cells in column GM.
I need a macro to go down column GM, and group any row where the value in column GM is "Hide". In some cases, only a single row will be grouped with a "+" sign. In other cases, consecutive rows will be grouped as such.
I want to go with grouping rather than filtering because with grouping, data hidden along the range of the dashboard is more readily accessible.
Any help would be greatly appreciated.
Thank you very much.
Last edited by JHCali; 05-23-2010 at 08:25 PM.
JHCali;
I'm curious; what do you mean by "Group"?
Hi Foxguy,
I am using Excel 2007. By group, I want the macro the accomplish what I would otherwise have to do by manually selecting individual or consecutive rows with a value of "Hide" in column GM, and going to the Data tab, selecting Group, then Group again. The Group feature in Excel ties a range of cells together so they can be expanded or collapsed.
JHCali;
I'm constantly learning things about Excel.
Try This
Sub Group_Hides() Dim rStart As Range, r As Range Dim lLastRow As Long, sColumn As String Dim rColumn As Range sColumn = "GM" lLastRow = Cells(Rows.Count, sColumn).End(xlUp).Row With ActiveSheet Set rColumn = .Range(.Cells(1, sColumn), Cells(lLastRow, sColumn)) With rColumn Set r = .Cells(1, 1) Do Until r.Row > lLastRow If rStart Is Nothing Then If r.Value = "Hide" Then Set rStart = r End If Else If r.Value <> "Hide" Then Range(rStart, r.Offset(-1, 0)).Rows.Group Set rStart = Nothing End If End If Set r = r.Offset(1, 0) Loop End With End With End Sub
Foxguy,
Worked brilliantly! Thank you so much!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks