-1

With ref to :- Automating group creation

I have a similar issue - whereby I am importing juniper code into excel and would like to group it - please see screenshot.

Issue is that in the original question the identifier was a ., in this case the identifier would be any row that didn't start with a space, and the grouping would be all rows until the next row that then started without a space. There is then the additional 'like' of coloring the line so that the group are easy to see.

Also, I think this is in the original question - the group then needs to expand downwards - not upwards.

Hope this makes sense.

Screenshot of example before and after here

screenshot of when script has run - notice - second section not grouped and start of group is above - would like it to be on the same line.

Community
  • 1
  • 1

1 Answers1

0

Try this

    Sub sda()
    lLastRow = Cells(Rows.Count, 1).End(xlUp).Row
    Set Rng = Range("A1:A" & lLastRow)
    For Each cell In Rng
    LResult = Left(cell.Value, 1)
    If LResult = " " Or IsEmpty(cell.Value) Then GoTo nxtCl:
    startRownum = cell.Row
    Set rng2 = Range("A" & startRownum + 1 & ":A" & lLastRow)
    For Each cll In rng2
    LResult = Left(cll.Value, 1)
    If LResult = " " Or IsEmpty(cell.Value) Then GoTo nxtCl2:
    endRownum = cll.Row
    Rows(startRownum + 1 & ":" & endRownum - 1).Group
    Exit For
    nxtCl2:
    Next
    nxtCl:
    Next
    End Sub

enter image description here

Maddy
  • 771
  • 5
  • 14
  • Whilst the response was quick and does in a way work, there is an issue. When run the script only does the first section, and places the group minus sign above the word. Could this be looked at. – Stephen C. Jun 21 '17 at 10:32
  • am trying to put a screenshot of it in the question - but finding it hard to do. – Stephen C. Jun 21 '17 at 10:37
  • edit your question and press `CTRL+G` to upload image ...refer https://stackoverflow.com/editing-help#images – Maddy Jun 21 '17 at 10:44
  • Great - that works fine - issue with my file as it stops for some reason but that's my issue. Also the grouping needs to be the other way around. if you do data > expand the outline section - in the settings then the top option is to summarize options below - disable that. – Stephen C. Jun 21 '17 at 12:30