View Full Version : Macro group rows


Luka
03-17-2009, 04:56 AM
Hi everyone.

I have excel file with structure:

a
bb
ccc
dd
e

What I want to achieve is to have a macro that will group all this rows. I am currently using this code:

Sub Group()
Dim i, j As Integer

i = 8
Cells(i, 1).Select

While Cells(i, 1).Text <> ""

For j = 1 To Selection.IndentLevel

Selection.Rows.Group

Next

i = i + 1
Cells(i, 1).Select
Wend

End Sub

Problem is because row does not always start at position 8. And second problem is if a run this macro three times in row I get error.

Thank you for your help.