Hey there,
I am trying to delete all the data on "Sheet1" of my spreadsheet except row 1 but using the code below, I keep getting an error when the macro is trying to calculate the end row and column, can any tell me where I am going wrong...and to stop me from going bonkers?!
Sub clear_sheet_content()
Dim oSheet As Excel.Worksheet
Dim col As Integer
Dim row As Integer
Set oSheet = Worksheets("Sheet1")
col = ActiveSheet.UsedRange.Columns.count
row = ActiveSheet.UsedRange.Rows.count + ActiveSheet.UsedRange.row - 1
On Error GoTo Errhandler
oSheet.Range(cells(2, 1), cells(row, col)).Select
Selection.ClearContents
Selection.NumberFormat = "General"
MsgBox "The sheet has been cleared", vbInformation, "Add Non Conformity"
Errhandler:
MsgBox "There is no data on sheet1", vbInformation, "Add Non Conformity"
End Sub
Cheers,
Jag
Bookmarks