Macro for replacement

miqueias

New Member
Joined
Feb 20, 2018
Messages
2
Hello,
I am using a macro to find & replace, but it work only when the cell has the value itself. I need the replace when he value contains in the cell, e.g.
My knowledge in vba is almost null, please help me


1a = X


A1 |A1
1atext should look like after replacement |Xtext
1b
text ----> |Xtext
1ctext |Xtext



Code:
Sub multisubstituir()On Error Resume Next
    Dim myList, myRange
    Set myList = Application.InputBox(prompt:="Select the modifications (2 columns)", _
    Title:="Tabela das Substituições", Type:=8)
    Set myRange = Application.InputBox(prompt:="Select the cells to replace", _
    Title:="Área a Substituir", Type:=8)
    For Each cel In myList.Columns(1).Cells
        myRange.Replace What:=cel.Value, _
        replacement:=cel.Offset(0, 1).Value, LookAt:=xlWhole
    Next cel
End Sub

Thanks :):)

edit: holy I messed everything up
1a = X
1b = Y
1c = Z

A1
1atext
1btext
1ctext
After replacement...

A1
Xtext
Ytext
Ztext
 
Last edited by a moderator:

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Whilst I don't understand what you are trying to do, try changing this
Code:
LookAt:=xlWhole
to
Code:
LookAt:=xlPart
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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