0

I have the data that I download from a software. The amount of a Column in First Level of Group shows the Sum of the amount in the Second Level of Group.

First Level Group

Second Level Group

What I need to do is clear the content in First Level to prevent duplication of amount for future calculation.

So, this is what i did. And how to make since the cell number is vary. Because if select the whole range F:F, its clear for all, first and second level.

Sub Macro3()
'
' Macro3 Macro
'

'
    ActiveSheet.Outline.ShowLevels RowLevels:=1
    Range("F2").Select
    Selection.ClearContents
    Range("F22").Select
    Selection.ClearContents
    Range("F82").Select
    Selection.ClearContents
    Range("F121").Select
    Selection.ClearContents
End Sub
Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
Biha
  • 97
  • 5
  • Please read up on [how to avoid using select](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba?rq=1). – Raymond Wu Nov 05 '21 at 09:48

1 Answers1

0

Make sure you hide all levels first, then you can use .SpecialCells(xlCellTypeVisible) to get only the visible cells and you can clear only those:

Option Explicit

Public Sub Example()
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Worksheets("Sheet1")

    ' hide all levels
    ws.Outline.ShowLevels RowLevels:=1

    ' clear only visible cells
    ws.Range("F:F").SpecialCells(xlCellTypeVisible).ClearContents
End Sub
Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73