Replace function - with wildcards

Formula11

Active Member
Joined
Mar 1, 2005
Messages
468
Office Version
  1. 365
Platform
  1. Windows
Do you know how to replace text-with-wildcard in a string.
Below code doesn't seem to work.

VBA Code:
simplify_text = "W(left_1_right)"
simplify_text = Replace(simplify_text, "W(*1*)", "W(1)")
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
VBA Code:
simplify_text = "W(left_1_right)"
If simplify_text Like "W(*1*)" Then simplify_text = "W(1)"
 
Upvote 0
Thanks for resolving.

What if this was required:
VBA Code:
Input:             part 1 + W(left_1_right) + part 3
Required output:   part 1 + W(1) + part 3
If I use the Like "*W(*1*)*", it gets rid of part 1 and part 3.
 
Upvote 0
The Replace function does not work with *, but the Replace method works with wildcard *

VBA Code:
Sub Macro1()

    Range("A1").Value = "part 1 + W(left_1_right) + part 3"
    Range("A1").Replace What:="W(*1*)", Replacement:="W(1)", LookAt:=xlPart
End Sub
 
Upvote 0
Thanks for posting.
This is within the editor though and not in Excel.
 
Upvote 0

Forum statistics

Threads
1,223,952
Messages
6,175,596
Members
452,657
Latest member
giadungthienduyen

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