Pasting a value into Filter search field using VBA Macro

matthewfreestone

New Member
Joined
May 29, 2012
Messages
26
Hi All,

Is there a way to use VBA to paste a value which has been copied (through VBA) into the Filter field. When recording my macro I start by using -

Range("E19").Select
Selection.Copy

However when I paste in VBA it pastes the value that is there currently. For example ...

ActiveSheet.Range("$A$1:$T$11596").AutoFilter Field:=5, Criteria1:= _
"Apples"

The problem that I have is that E19 is a field that will change based on information that is added to this sheet every day. So today it may show Apples, but tomorrow it may show Oranges, though the Macro has recorded to set the filter to Apples again.

Any help would be greatly appriciated.

Thanks,
Matt
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Code:
ActiveSheet.Range("$A$1:$T$11596").AutoFilter Field:=5, Criteria1:= _
 Range("E19").Value
 
Upvote 0
Hi BarryL

Thanks for the response, however I missed one piece of quite important information... the data is Field E19, is in Workbook 1, and the data that needs filtering is in the range ("$A$1:$T$11596") on a seperate Workbook. Hence why I thought we needed a copy/paste solution.

Thanks,
Matt
 
Upvote 0
Hi BarryL

Thanks for the response, however I missed one piece of quite important information... the data is Field E19, is in Workbook 1, and the data that needs filtering is in the range ("$A$1:$T$11596") on a seperate Workbook. Hence why I thought we needed a copy/paste solution.

Thanks,
Matt
Hi Matt,

Does this get you moving in the right direction?

Code:
Sub YourMacroName()
Dim FilterString As String
FilterString = Workbooks("[COLOR=#ff0000][B]Workbook1.xlsx[/B][/COLOR]").Sheets("[COLOR=#ff0000][B]SheetName[/B][/COLOR]").Range("E19").Value
ActiveSheet.Range("$A$1:$T$11596").AutoFilter Field:=5, Criteria1:= FilterString
End Sub

[EDIT] - Obviously amend the bold red parts to suit the correct workbook name and sheet name
 
Last edited:
Upvote 0
Hi Fishboy,

That does indeed look like that will do the trick, will give it a try when back at the office tomorrow. Thanks alot!
 
Upvote 0
Hi Fishboy,

That does indeed look like that will do the trick, will give it a try when back at the office tomorrow. Thanks alot!
Hey fishboy and mathew,

i am able to make macro from above but want to search like below
The current search needs and exact match
%Appl%
so even if apple is not perfect and i have word related to appla or appli then also the output will be shown
any suggestions on the same
 
Upvote 0

Forum statistics

Threads
1,216,101
Messages
6,128,845
Members
449,471
Latest member
lachbee

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