Excel auto filter VBA code help needed

Javi

Active Member
Joined
May 26, 2011
Messages
440
I have a sheet with data in columns A thur F and the auto filter set on. In Column E (field 5) the sort is working well it filter all values as needed (I only wanted 0 selected). My problem is the next 2 sorts won’t work.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>
I would like to have everything selected but 0 and blanks to be excluded. I need the order to be Column D (Field 4) then Column F (Field 6). Below is what I tried and failed.
<o:p> </o:p>
<o:p> </o:p>
Sub O_Use_StoLoc_Sheet_Macro()
'
' O_Use_StoLoc_Sheet_Macro Macro
'
ActiveSheet.Unprotect

Columns("A:F").Select
Selection.AutoFilter

ActiveSheet.Range("$A$1:$F$40001").AutoFilter Field:=5, Criteria1:="0"
ActiveSheet.Range("$A$1:$F$40001").AutoFilter Field:=4, Criteria1:="<>"0, _
ActiveSheet.Range("$A$1:$F$40001").AutoFilter Field:=6, Criteria1:="<>"0, _
<o:p> </o:p>
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowSorting:=True, AllowFiltering:=True, AllowUsingPivotTables:=True
<o:p> </o:p>
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Try changing these two lines

ActiveSheet.Range("$A$1:$F$40001").AutoFilter Field:=4, Criteria1:="<>"0, _
ActiveSheet.Range("$A$1:$F$40001").AutoFilter Field:=6, Criteria1:="<>"0, _

To ~

ActiveSheet.Range("$A$1:$F$40001").AutoFilter Field:=4, Criteria1:="<>0"
ActiveSheet.Range("$A$1:$F$40001").AutoFilter Field:=6, Criteria1:="<>0"

Cheers
 
Upvote 0
Try changing these two lines

ActiveSheet.Range("$A$1:$F$40001").AutoFilter Field:=4, Criteria1:="<>"0, _
ActiveSheet.Range("$A$1:$F$40001").AutoFilter Field:=6, Criteria1:="<>"0, _

To ~

ActiveSheet.Range("$A$1:$F$40001").AutoFilter Field:=4, Criteria1:="<>0"
ActiveSheet.Range("$A$1:$F$40001").AutoFilter Field:=6, Criteria1:="<>0"

Cheers
Worked Great Thanks,

Something so Small cost me hours!!!
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,278
Members
452,902
Latest member
Knuddeluff

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