I'm looking to create a macro to group rows based on cell content. Each new invoice begins with H with rows under beginning with N, the number of N rows varies with different invoices. What i want to do it create a macro that will add one row break between each invoice including all the N rows relevant to it. I hope this makes sense.
For example the orignal invoice file looks like this...
H
N
N
H
N
H
N
but i want to run a macro to make it look like this
H
N
N
H
N
H
N
I am currently running this macro
Columns("A:B").Select
Range("B1").Activate
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'next part below inserts a row where there is a z. "A" is the first blank row on the report where it should stop looping
Dim i As Long, c As Range
Set c = Range("a1") 'my data starts at row 7
Do Until c.Value = "A"
If c.Value = "H" Then
c.EntireRow.Insert
Else
End If
Set c = c.Offset(1)
Loop
'next part goes through and groups the rows with an "x" in col a. It goes line by line but as i said earlier, if they're next to one another, it will group them together
Set c = Range("a7")
Do Until c.Value = "A"
If c.Value = "N" Then
c.EntireRow.Group
Else
End If
Set c = c.Offset(1)
Loop
'next compacts the outline
ActiveSheet.Outline.ShowLevels RowLevels:=1
Range("a1").Select
but i keep getting this error
run-time error '1004'
Application-defined or object-defined error