View Full Version : Macro to delete rows


tinynoo
08-26-2009, 04:53 AM
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:

HaHoBe
08-26-2009, 06:32 AM
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):

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).E ntireRow.Delete
.AutoFilter
End With
End Sub
Ciao,
Holger

tinynoo
08-26-2009, 07:28 AM
Thanks for your help, will give this a try.