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(.
The issue is not with the with statement, it is on the Range function, it doesn't accept the absolute cell value.. it should be like Range("A4:B100").. you can refer the following thread for reference..
following code should work.. Convert cells(1,1) into "A1" and vice versa
LastColData = Sheets(WSNAME).Range("A4").End(xlToRight).Column
LastRowData = Sheets(WSNAME).Range("A4").End(xlDown).Row
Rng = "A4:" & Sheets(WSNAME).Cells(LastRowData, LastColData).Address(RowAbsolute:=False, ColumnAbsolute:=False)
Worksheets(WSNAME).Range(Rng).ClearContents