PDA

View Full Version : Sleeper: Macro to delete rows in result of advanced filter.



uktous
02-01-2014, 08:07 AM
Hi,

Could you please create a macro which can perform this function?

3 features
After I use advanced filter, I will run the macro and the macro will delete all rows in the result of the advanced filter.
The macro will not delete the row for heading.
If the result of advanced filter has nothing, the macro wil not delete anything.

Thanks

ashleyuk1984
02-01-2014, 08:56 AM
Sub test()


Range("A1").Select
If Range("A9999").End(xlUp).Address = "$A$1" Then
Exit Sub
Else
ActiveCell.Offset(1, 0).Select
If Cells(Columns("A").Rows.Count, "A").End(xlUp).Row > 2 Then
Range(Selection, Cells(Columns("A").Rows.Count, "D").End(xlUp)).SpecialCells(xlCellTypeVisible).Select
Else
End If
Selection.EntireRow.Delete
End If

End Sub


See if this completes the task for you.

This assumes that your list starts at A1, and has four columns of data.

pmyk
02-02-2014, 10:46 PM
I think the selection line should be altered as :


Range(Selection, Cells(Columns("A").Rows.Count, "A").End(xlUp)).SpecialCells(xlCellTypeVisible).Select

ashleyuk1984
02-03-2014, 11:55 AM
Well, like I said, my code assumes that he has FOUR columns of data. Hense the "D". It's easier to point this out to the OP so that he can then make his own adjustments accordingly.

pmyk
02-03-2014, 09:56 PM
Ok, got it.

mancubus
02-04-2014, 05:06 AM
assumtion: top left cell of the contiguous range is A1
Sheets("MySheet").UsedRange.Columns(1).Offset(1).SpecialCells(xlCellTypeVisible).EntireRow. Delete