Notice: WC_Cart::get_cart_url is deprecated since version 2.5! Use wc_get_cart_url instead. in /home/swatipaliwal/public_html/excelcrazy.com/wp-includes/functions.php on line 3839
Excel Crazy

How to delete rows in Excel using VBA based on the criteria?

 

Most of the time while formatting sheets of data we remove immaterial rows from the data.

So here is the simple example, below macro will delete the all rows containing “Grand Total” in the column A.

To run the macro use following steps:

  • Open VBA (Visual Basic Editor), Press Alt + F11.
  • Go to Insert>Module.
  • Copy the code and paste it in the new module.
  • Press Alt+Q to return to Excels sheets.
  • Push Alt+F8 (Or click Developer Tab > Macros) and then select the macro name and click Run. 
Sub Deletingrows()

Dim i As Long, lastrow As Long

lastrow = Cells(Rows.Count, 1).End(xlUp).Row

For i = lastrow To 1 Step -1

  If Cells(i, 1).Value = "Grand Total" Then
      Rows(i).Delete
  End If

Next i

End Sub
September 28, 2015

1 responses on "How to delete rows in Excel using VBA based on the criteria?"

  1. hi
    dear

    thanks for that course nice and craze excel
    thanks i like to here more for user form
    thanks all staff.

    raymond

Leave a Message

Your email address will not be published. Required fields are marked *

top
 

© LOKESH PALIWAL 1987 - 2017

Reporting Solutions | Data Consulting | Analytics Training