Clear contents of cells in VBA using column reference

后端 未结 8 1776
没有蜡笔的小新
没有蜡笔的小新 2021-01-01 22:31

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(.         


        
8条回答
  •  醉梦人生
    2021-01-01 23:11

    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
    

提交回复
热议问题