VBA code to Filter by Begins with xx and 1

NZAS

Board Regular
Joined
Oct 18, 2012
Messages
117
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have a VBA code that does some filtering but would like to change it so it filters by using the begins with "MF" and also there is 1 in some of the rows.
Original code is below was create by some one else and I would like to change the criteria 1 and 2 to be a single criteria that would be begins with "MF" and also a criteria "1"
where the "1" in the data is a line break to show different days of week. The final out put should on display the rows where the "1" is as well as any rows That begins with "MF" from the wharf/ destination column which is field14

Original VBA that needs to be changed

With Sheets("Dispatch Sheet")
Range("A2:P2").Select
Selection.AutoFilter
ActiveSheet.Range("$A$2:$P$77").AutoFilter Field:=14, Criteria1:="=MFINGOT", _
Operator:=xlOr, Criteria2:="=MFBILLET"

Below is the data

1590456668387.png


Cheers
NZAS
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hello NZAS,

See if the following works for you:-

VBA Code:
Sub Test()

        With Sheets("Dispatch Sheet").Range("A2:P2")
               .AutoFilter 14, "*" & "MF" & "*", xlOr, 1
        End With

End Sub

I hope that this helps.

Cheerio,
vcoolio.
 
Upvote 0
How about
VBA Code:
Sub NZAS()
   With Sheets("Dispatch Sheet")
      .Range("A1:P" & .Range("A" & Rows.Count).End(xlUp).Row).AutoFilter 14, "MF*", xlOr, "1"
   End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,978
Messages
6,122,549
Members
449,089
Latest member
davidcom

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