Thursday, 23 May 2013

Macro to clear contents of certain cells in Excel sheet

Example -

In below example I am going to show you how we can clear the contents of specified cells  in excel sheet.
I will also show you how we can use macro to clear the contents of entire row or column.

Code and Syntax to clear the contents of specified cells using macro.

Code to clear the contents of certain cell.
    Range("A18").Select
    Selection.ClearContents
   

Code to clear the contents of multiple cells.
    Range("A2:B22").Select       ' clear contents of a range
    Selection.ClearContents



Code to clear the contents of Entire row in Excelsheet
    rows("2:2").Select
    Selection.ClearContents


Code to clear the contents of Entire Column in Excelsheet
    columns("A:A").Select
    Selection.ClearContents


In similar way we can clear the contents of any cells, ranges in excel sheet using VBA macro. It is just two step process.
  • Select the area/region you want to clear.
  • Use Selection.ClearContents statement.

No comments:

Post a Comment

Popular Posts

Search This Blog