VBA / AdvancedFilter exact result

amarokWPcom

New Member
Joined
May 30, 2019
Messages
25
Hi,

I put a filter with AdvancedFilter.

For some search strings I get to manz results.
So f.e. for "John" I get also"Johnsson", "Johnson" etc., everzthing that fits to John*.

I know already by using the string ="=John" that I would get ONLY "John" like I want.

But my Subroutine has not a string as searchterm but a variable as you can see bellow.

How do I have to change the code bellow to make this work????


HTML:
Sub DISTRIBUTIONLIST_SEARCH()

Dim WS_DIST_SOURCE As Worksheet
Dim WS_DIST_RESULTS As Worksheet

Set WS_DIST_RESULTS = ThisWorkbook.Worksheets("DISTRIBUTE_RESULT")
Set WS_DIST_SOURCE = ThisWorkbook.Worksheets("DISTRIBUTE_LIST")

WS_DIST_RESULTS.Range("A1").CurrentRegion.Offset(1).ClearContents

Dim rg4 As Range
Set rg4 = WS_DIST_SOURCE.Range("A1").CurrentRegion

Dim criteriaRange4 As Range
Set criteriaRange4 = ThisWorkbook.Worksheets("DISTRIBUTE_DISCRIPTION").Range("A2"). _
CurrentRegion

' THE MAIN Code
rg4.AdvancedFilter xlFilterCopy, criteriaRange4, WS_DIST_RESULTS.Range("A1:D1")

End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
How are you entering the search term into criteriaRange4? There is nothing in your code that does that.
 
Upvote 0
Hi Fluff,
Dim criteriaRange4 As Range
Set criteriaRange4 = ThisWorkbook.Worksheets("DISTRIBUTE_DISCRIPTION").Range("A2"). _
CurrentRegion

Here the string will be put by the code before.

Do you mean I should put the string at this place like....
....
Worksheets("DISTRIBUTE_DISCRIPTION").Range("A2").value = Worksheets("DISTRIBUTE_DISCRIPTION").Range(... = "=<code>" & Chr(34) &</code> "=" & string & "
 
Upvote 0
This line
Code:
Set criteriaRange4 = ThisWorkbook.Worksheets("DISTRIBUTE_DISCRIPTION").Range("A2"). _
CurrentRegion
Is just setting a range variable, it is not putting the search criteria into the that range. So how are you entering the criteria in A3?
 
Upvote 0
I found it out by your first answer ;)

I write the input by VBA as value in
Worksheets("DISTRIBUTE_DISCRIPTION").Range("A2")

No I changed it to Worksheets("DISTRIBUTE_DISCRIPTION").Range("A2").Value = "=" & Chr(34) & "=" & Worksheets("PARAMETER").Range("B113").Value & Chr(34) & ""

And I think it works. Many thanks
 
Upvote 0
Glad you sorted it & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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