Search code examples
excelvbaparentoutline

Flattening Outlined Data then rebuild Outlines again


To my fellow peers,

Basically I have an extract of a BOM from a business system which generates an outlined report (no template just pushes the data into an excel sheet). An example of which looks like the below:

enter image description here

I need to flatten this extract to perform some manipulation is there anyway using the columns shown I can rebuild the Outline groupings again to how it was?

Thankyou


Solution

  • Public Sub SetOutline()
    
      Dim i As Long
    
      With [A:A].Cells                        'column containing levels
        For i = 1 To .Count
          If IsEmpty(.Item(i)) Then Exit For  'quit at first blank cell
          .Item(i).EntireRow.OutlineLevel = .Item(i).Value + 1 'set outline
    '      .Item(i).EntireRow.ClearOutline    'this would remove the outline
        Next i
      End With
    
    End Sub