Need help with an excel macro to group values

A

aman

I am looking to group cells in excel. I have a column called level
and the levels range from 4-6.

4
5
5
5
6
6
5
6
6
4
5
5
5
6
6
5

Group at level 4 (so select all rows with a 5 or 6 until you reach the
next level 4)
Then group at level 5 (so select all rows with a 6 and group them with
the 5 above them)

I don't know any coding so if you could please assist me with this.

Thanks
 
H

Héctor Miguel

hi, !

assuming your column(range) is A2:A17 and you wan to group-outline -?-
try with a macro like this one:

Sub OutLineRows_Base_4To6()
Dim eCell As Range
Application.ScreenUpdating = False
For Each eCell In Range("a2:a17")
If eCell > 3 And eCell < 7 Then _
eCell.EntireRow.OutlineLevel = eCell - 3
Next
End Sub

hth,
hector.

__ original post __
 
A

aman

hi, !

assuming your column(range) is A2:A17 and you wan to group-outline -?-
try with a macro like this one:

Sub OutLineRows_Base_4To6()
Dim eCell As Range
Application.ScreenUpdating = False
For Each eCell In Range("a2:a17")
If eCell > 3 And eCell < 7 Then _
eCell.EntireRow.OutlineLevel = eCell - 3
Next
End Sub

hth,
hector.

__ original post __

Hector, the macro works great. You have been great help. Is it
possible to run the macro for all the worksheets? I have about 10
sheets in the excel workbook. If I could run it for all the sheet
instead of just running the macro for each sheet, it would save a lot
of time.

Thanks,
Aman
 
H

Héctor Miguel

hi, aman !
... Is it possible to run the macro for all the worksheets?
I have about 10 sheets in the excel workbook.
If I could run it for all the sheet instead of just running the macro for each sheet, it would save a lot of time.

could it be someting like:

Sub OutLineRows_Base_4To6()
Dim nSheet As Worksheet, eCell As Range
Application.ScreenUpdating = False
For Each nSheet In Worksheets
With nSheet
For Each eCell In .Range( _
.Range("a2"), .Range("a65536").End(xlUp))
If eCell > 3 And eCell < 7 Then _
eCell.EntireRow.OutlineLevel = eCell - 3
Next
End With
Next
End Sub

hth,
hector.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top