Buddha_420
New Member
Hello guys,
I'm running a macro to conditionally group rows based on cell values (if cell in column B = "n/a"). The thing is that I want some rows to remain grouped at all time and have some of these already grouped rows to be grouped to level 2 if the aforementioned condition is met.
The issue with the code below is that if I run the macro more than once, some rows will be grouped more than twice (which is what I want to avoid). I thus need to have level 2 grouped rows to be ungrouped before checking for the condition and grouping but can't find the code for that.
Thanks for helping!
See the code below:
I'm running a macro to conditionally group rows based on cell values (if cell in column B = "n/a"). The thing is that I want some rows to remain grouped at all time and have some of these already grouped rows to be grouped to level 2 if the aforementioned condition is met.
The issue with the code below is that if I run the macro more than once, some rows will be grouped more than twice (which is what I want to avoid). I thus need to have level 2 grouped rows to be ungrouped before checking for the condition and grouping but can't find the code for that.
Thanks for helping!
See the code below:
Code:
Option Explicit
Sub GroupRows()
Dim rData, rCel As Range
Set rData = Range("b47", Range("b" & Rows.Count).End(xlUp))
Application.ScreenUpdating = False
With rData
On Error Resume Next
.Rows.EntireRow.Hidden = False
On Error GoTo 0
End With
For Each rCel In rData
If rCel = "END" Then Exit For
If rCel = "n/a" Then
Rows(rCel.Row).Group
rCel.EntireRow.Hidden = True
End If
Next
Application.ScreenUpdating = True
End Sub
Last edited by a moderator: