frantheman97
New Member
- Joined
- Jul 4, 2022
- Messages
- 2
- Office Version
- 365
- Platform
- Windows
Hi guys,
I'm trying to delete cells that are different to "0" or "-".
But, I'm having the problem that the macro is deleting in all the worksheet, instead of the specific range.
Do you know how can I do to delete in a specific range?
I want to determine range ("b8,Aj861",.end(xldown)), but the last row must be the last value. and I dont know why it doesnt work.
Also, I would like not to delete the title or the filter row.
Thanks for your help.
I'm trying to delete cells that are different to "0" or "-".
But, I'm having the problem that the macro is deleting in all the worksheet, instead of the specific range.
Do you know how can I do to delete in a specific range?
I want to determine range ("b8,Aj861",.end(xldown)), but the last row must be the last value. and I dont know why it doesnt work.
Also, I would like not to delete the title or the filter row.
VBA Code:
Sub prueba()
Dim ws As Worksheet
Dim rng1 As Range
Set ws = ActiveSheet
' I want to determine this range, but the last row must be the last value.
Set rng1 = ws.Range("b8:aj861")
'Reset Existing Filters
On Error Resume Next
ws.ShowAllData
On Error GoTo 0
'Apply Filter
rng1.AutoFilter Field:=20, Criteria1:="<>-", _
Operator:=xlAnd, Criteria2:="<>0"
'Delete Rows
Application.DisplayAlerts = False
rng1.SpecialCells(xlCellTypeVisible).Delete
Application.DisplayAlerts = True
'Clear Filter
On Error Resume Next
ws.ShowAllData
On Error GoTo 0
End Sub
Thanks for your help.