Siraj
Siraj

Reputation: 195

Macro to clear contents including format in a column

I want to clear contents including format in column G till the last data in the column. Note column G also has some empty cells in between. I used below code it works fine but it clears data from all columns. Please any help will be appreciated.

Sub ClearData()
Range("A3", Columns("A").SpecialCells(xlCellTypeLastCell)).Clear
MsgBox ("Data Cleared")
End Sub

Thanks

Upvotes: 0

Views: 1268

Answers (1)

Shai Rado
Shai Rado

Reputation: 33682

The code below will ClearContents and ClearFormats from column "G" (starting from "G3" until last row with data in column "G")

Sub ClearData()

With Range("G3:G" & Cells(Rows.Count, "G").End(xlUp).Row)
    .ClearContents
    .ClearFormats
End With
MsgBox "Data Cleared"

End Sub

Upvotes: 2

Related Questions