VBA .Find WildCard not working

Akbarov

Active Member
Joined
Jun 30, 2018
Messages
347
Office Version
  1. 365
Platform
  1. Windows
Hello, I am trying to use Wild card in .Find with variables. You can see in attachment below.
But for some reason it is not finding. Can anyone tell me where I do wrong?

VBA Code:
                    For xW1 = 1 To 30
                            With Selection.Find
                    .Text = "*" & SozX(xW1) & "*" & SozX(xW1 + 1) & "*" & SozX(xW1 + 2) & "*" & SozX(xW1 + 3) & "*" & SozX(xW1 + 4) & "*" & SozX(xW1 + 5) & "*"
                    .Replacement.Text = ""
                    .Forward = True
                    .Wrap = wdFindContinue
                    .Format = False
                    .MatchCase = False
                    .MatchWholeWord = False
                    .MatchWildcards = False
                    .MatchSoundsLike = False
                    .MatchAllWordForms = False
                    End With
                    If Selection.Find.Found = True Then MsgBox ("Tapildi")
                    Next xW1

Thanks in advance.
 

Attachments

  • findvariable.png
    findvariable.png
    8.9 KB · Views: 12

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
A possible work-around could be:
VBA Code:
For xW1 = 1 To 30
  If UCase(Selection.Value2) Like UCase("*" & SozX(xW1) & "*" & SozX(xW1 + 1) & "*" & SozX(xW1 + 2) & "*" & SozX(xW1 + 3) & "*" & SozX(xW1 + 4) & "*" & SozX(xW1 + 5) & "*") Then MsgBox ("Tapildi")
Next xW1
 
Upvote 0
Thanks for reply, but I use that code to find string within paragraph in Word and select that paragraph. With your code I don't think I can do that.
 
Upvote 0
Thanks for reply, but I use that code to find string within paragraph in Word and select that paragraph. With your code I don't think I can do that.
Yes, the detail about trying to do this in Word is a very important detail that you want to be sure to mention when you first post your question (especially since this is mostly an Excel forum)!
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,207
Members
452,618
Latest member
Tam84

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