Macro to delete rows

tinynoo

Registered User.
Local time
Today, 03:28
Joined
Apr 15, 2008
Messages
14
Can someone help; I have attached spreadsheet with 3 columns. I want a macro to delete rows which have 'Site' in the 1st column and/or 'Refund [Debit]' in the 2nd column.

I have no knowledge of VB code but am still hopeful this can be simple! :eek:
 

Attachments

Hi, tinynoo,

make use of the Autofilter for it (could be achieved without macros as well). Code goes into a normal module, starts the Autofilter, puts the items into the columns and then deletes all visible rows from row 2 to the end. At the end the Autofilter is resolved. Please mind that there may occur a runtime error if no cells are meeting your criteria (if the macro is run a second time the headings will be deleted):

Code:
Sub myMacro()
With Range("A1:C1")
  .AutoFilter
  .AutoFilter Field:=1, Criteria1:="Site"
  .AutoFilter Field:=2, Criteria1:="Refund [Debit]"
  Range("A2:C" & Cells(Rows.Count, "A").End(xlUp).Row).SpecialCells(xlCellTypeVisible).EntireRow.Delete
  .AutoFilter
End With
End Sub
Ciao,
Holger
 
Thanks for your help, will give this a try.
 

Users who are viewing this thread

Back
Top Bottom