Delete rows/columns/cell data using a macro in an excel report
You can delete the entire row and/or columns and/or just clear the cells much quicker automatically than manually, particularly, if you have to do it many times during the month but if you are doing this task once a year, forget about it.
When I use the macro ?
When I extract data from a program or from an intranet webpage, for instance, some data are merged in many columns and I need to delete those unnecessary columns.
How to create the macro ?
Read How to create, edit, hide and select a macro in an excel report
How to create the button to associate it with the macro ?
Read How to create a button and associated it to a macro in an excel report
How is/are the macro(s) ?
Copy the code below and paste it into your macro. You will see my comments in green if exist so follow the help to adapt to your need.
To delete columns:
Sub test() ' delete entire columns C and from E to G ActiveSheet.Range("C:C,E:G").EntireColumn.Delete End Sub
To delete rows:
Sub test() ' delete entire rows from row 2 to row 50 ActiveSheet.Range("A2:A50").EntireRow.Delete End Sub
To clear contents:
Sub test() ' delete all data in cells from A2 to G50 ActiveSheet.Range("A2:G50").ClearContents End Sub
Interesting Topics
-
Be successfully certified ITIL 4 Managing Professional
Study, study and study, I couldn’t be successfully certified without studying it, if you are interested...
-
Be successfully certified ITIL 4 Strategic Leader
With my ITIL 4 Managing Professional certification (ITIL MP) in the pocket, it was time to go for the...
-
Hide visual and change background color based on selection
Some small tricks to customize the background colour of a text box...
-
Stacked and clustered column chart or double stacked column chart
In excel, I use a lot the combination of clustered and stacked chart...