Can anyone show me how to Clear the content of a sheet without clearing the first Row and Column G?

Regards Brian

2 Answers

Community On Best Solutions


Range("A2:F" & Rows.Count).ClearContents
Range("H2", Cells(Rows.Count, Columns.Count)).ClearContents
user3598756 On

you could use a SpecialCells() method flavor to act (i.e. ClearContents) on visible cells only, as follows:

Sub main()
    HideMyFavorites True '<--| hide your favorite rows/columns
    Cells.SpecialCells(xlCellTypeVisible).ClearContents '<--| clear the content of "visible" cells only
    HideMyFavorites False '<--| unhide your favorite rows/columns
End Sub

Sub HideMyFavorites(doHide As Boolean)
    Columns(7).Hidden = doHide '<--| hide/unhide column "G" (whose column index of "7")
    Rows(1).Hidden = doHide '<--| hide/unhide row "1"
End Sub