I am trying to get a piece of code to clear the data in some cells, using the column references. I am using the following code:
Worksheets(sheetname).Range(.
You can access entire column as a range using the Worksheet.Columns
object
Something like:
Worksheets(sheetname).Columns(1).ClearContents
should clear contents of A column
There is also the Worksheet.Rows
object if you need to do something similar for rows
The error you are receiving is likely due to a missing with block.
You can read about with blocks here: Microsoft Help
I found this an easy way of cleaning in a shape between the desired row and column. I am not sure if this is what you are looking for. Hope it helps.
Sub sbClearCellsOnlyData()
Range("A1:C10").ClearContents
End Sub