Clear contents of cells in VBA using column reference

后端 未结 8 1778
没有蜡笔的小新
没有蜡笔的小新 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:25

    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

    0 讨论(0)
  • 2021-01-01 23:26

    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
    
    0 讨论(0)
提交回复
热议问题