Clear contents of cells in VBA using column reference

后端 未结 8 1785
没有蜡笔的小新
没有蜡笔的小新 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条回答
  •  -上瘾入骨i
    2021-01-01 23:15

    To clear all rows that have data I use two variables like this. I like this because you can adjust it to a certain range of columns if you need to. Dim CRow As Integer Dim LastRow As Integer

    CRow = 1
    LastRow = Cells(Rows.Count, 3).End(xlUp).Row
    
    Do Until CRow = LastRow + 1
        Cells(CRow, 1).Value = Empty
        Cells(CRow, 2).Value = Empty
        Cells(CRow, 3).Value = Empty
        Cells(CRow, 4).Value = Empty
        CRow = CRow + 1
    Loop
    

提交回复
热议问题