VBA macro that filters two criteria in one column and grabs top 8 in another column

bored622

New Member
Joined
Mar 2, 2022
Messages
43
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone,

I'm trying to make a macro button that when clicked on it filters two criteria from column M and filters the top eight from column C.

This is what I got so far:

VBA Code:
Sub Filterfp()

With Worksheets("WaveFile").Range("A6")
.AutoFilter Field:=13, Criteria1:="FP", Operator:=xlOr, Criteria2:="BK"
.AutoFilter Field:=3, Criteria1:="8", Operator:=xlTop10Items

End With

End Sub
 
Would there be a way to convert from C7 down from text to numbers in VBA?
Try this

VBA Code:
Sub Filterfp_v3()
  Dim dVal As Double

  With Worksheets("WaveFile").Range("A6").CurrentRegion
    .Columns(3).Replace What:="-", Replacement:="", Lookat:=xlPart
    .AutoFilter Field:=13, Criteria1:="FP", Operator:=xlOr, Criteria2:="BK"
    dVal = .Worksheet.Evaluate(Replace("AGGREGATE(14,6," & .Columns(3).Address & "/((#=""FP"")+(#=""BK"")),8)", "#", .Columns(13).Address))
    .AutoFilter Field:=3, Criteria1:=">=" & dVal
  End With
End Sub

This is what I ended up with from that earlier sample data (I've hidden the other columns to keep the mini sheet small)

bored622.xlsm
CM
6DPCIPull Mode
797110681FP
831110815FP
931110851FP
1031111021FP
1431110297BK
1531110480BK
1631110676BK
1731110678BK
26
WaveFile
 
Upvote 0
Solution

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try this

VBA Code:
Sub Filterfp_v3()
  Dim dVal As Double

  With Worksheets("WaveFile").Range("A6").CurrentRegion
    .Columns(3).Replace What:="-", Replacement:="", Lookat:=xlPart
    .AutoFilter Field:=13, Criteria1:="FP", Operator:=xlOr, Criteria2:="BK"
    dVal = .Worksheet.Evaluate(Replace("AGGREGATE(14,6," & .Columns(3).Address & "/((#=""FP"")+(#=""BK"")),8)", "#", .Columns(13).Address))
    .AutoFilter Field:=3, Criteria1:=">=" & dVal
  End With
End Sub

This is what I ended up with from that earlier sample data (I've hidden the other columns to keep the mini sheet small)

bored622.xlsm
CM
6DPCIPull Mode
797110681FP
831110815FP
931110851FP
1031111021FP
1431110297BK
1531110480BK
1631110676BK
1731110678BK
26
WaveFile
Worked perfectly. thank you
 
Upvote 0

Forum statistics

Threads
1,214,391
Messages
6,119,239
Members
448,879
Latest member
VanGirl

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