containing filter macro

Binky

New Member
Joined
May 27, 2011
Messages
2
Hi all,

I am trying to make a button to use the containing filter on my spreadsheet. From what I have read on the web the macro I have should work but it is filtering out all the data. When I put Criteria1:="*=civil*" in the spreadsheet I get the correct cells being shown but then if I change it to Criteria1:=str and put civil in cell B5 I get nothing. I am a VB noob so any help would be greatly appreciated.



Sub search()
'
' search Macro
'
Dim str As String
str = Range("B5").Value

ActiveSheet.Range("$A$10:$D$490").AutoFilter Field:=3, Criteria1:=str _
, Operator:=xlAnd
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Try

Code:
ActiveSheet.Range("$A$10:$D$490").AutoFilter Field:=3, Criteria1:="*" & Str & "*", Operator:=xlAnd
 
Upvote 0

Forum statistics

Threads
1,224,594
Messages
6,179,792
Members
452,942
Latest member
VijayNewtoExcel

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