# Replace function - with wildcards



## Formula11 (Dec 26, 2022)

Do you know how to replace text-with-wildcard in a string.
Below code doesn't seem to work. 


```
simplify_text = "W(left_1_right)"
simplify_text = Replace(simplify_text, "W(*1*)", "W(1)")
```


----------



## Phuoc (Dec 26, 2022)

```
simplify_text = "W(left_1_right)"
If simplify_text Like "W(*1*)" Then simplify_text = "W(1)"
```


----------



## Formula11 (Dec 26, 2022)

Thanks for resolving.

What if this was required:

```
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.


----------



## Phuoc (Dec 26, 2022)

The Replace function does not work with *, but the Replace method works with wildcard  *


```
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
```


----------



## Formula11 (Dec 26, 2022)

Thanks for posting.
This is within the editor though and not in Excel.


----------

