HELP- Macro Stopped Working

Delta Star

Board Regular
Joined
Oct 28, 2009
Messages
184
I don't know why but this piece of code has stopped working correctly. Once it has set the filter and selected those with 0, it not only clears those cells with a 0 but all the others as well.

What have I done wrong?

Range("A1:F1").Select
Range("F1").Activate
Application.CutCopyMode = False
Selection.AutoFilter
Range("A2:F" & LastRowA + 1).Select
Range(Selection, Selection.End(xlDown)).Select
Range("A2:F" & LastRowA + 1).Select
Range("F2").Activate
Selection.AutoFilter Field:=5, Criteria1:=0
Selection.ClearContents
Selection.AutoFilter
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
I recorded the macro again and it came up with a warning message about it being too complex. Sorted it numericall and it now works.
 
Upvote 0
Hi,

Try this:

Code:
    LastRowA = Range("A" & Rows.Count).End(xlUp).Row
    If ActiveSheet.AutoFilterMode = False Then Range("A1:F1").AutoFilter
    Range("A1:F1").AutoFilter Field:=5, Criteria1:=0
    Range("A2:F" & LastRowA).SpecialCells(xlCellTypeVisible).ClearContents
 
Upvote 0
Try:
Code:
Sub AliensHaveStolenMyShorts ()
Dim i As Long
 
Application.ScreenUpdating = False
 
If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
i = Range("F" & Rows.Count).End(xlUp).Row
 
With Range("A1:F" & i)
 .AutoFilter
 .AutoFilter field:=5, Criteria1:=0
End With
 
ActiveSheet.UsedRange.Offset(1, 0).Resize(ActiveSheet.UsedRange.Rows.Count - 1).ClearContents
ActiveSheet.AutoFilterMode = False
 
Application.ScreenUpdating = True
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,678
Members
452,937
Latest member
Bhg1984

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top