VBA Multiple Find and Replace Amendment

hblbs

Board Regular
Joined
Mar 18, 2009
Messages
184
Hi all, I hope you can help with the code below which was taken from an online source "Ktools for Excel", this seems to work but needs adapting in the following way.

Is anyone able amend this so that the replace range can "Match by case" and "Match entire cell contents"?

Code:
[Sub MultiFindNReplace()
Dim Rng As Range
Dim InputRng As Range, ReplaceRng As Range
xTitleId = "KutoolsforExcel"
Set InputRng = Application.Selection
Set InputRng = Application.InputBox("Original Range ", xTitleId, InputRng.Address, Type:=8)
Set ReplaceRng = Application.InputBox("Replace Range :", xTitleId, Type:=8)
Application.ScreenUpdating = False
For Each Rng In ReplaceRng.Columns(1).Cells
    InputRng.Replace What:=Rng.Value, Replacement:=Rng.Offset(0, 1).Value
Next
Application.ScreenUpdating = True
End Sub

To somehow include the following two lines.

Code:
Selection.Replace What:="a", Replacement:="", LookAt:=xlWhole, MatchCase:=True

Thanks in advance.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Try
Code:
inputrng.Replace rng.Value, rng.Offset(0, 1).Value, xlWhole, , True, , False, False
 
Upvote 0
Thank you, this appears to be the way to do it. By putting the whole values it finds and replaces the details.

Code:
InputRng.Replace What:=Rng.Value, Replacement:=Rng.Offset(0, 1).Value, LookAt:=xlWhole, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False

********SOLVED****************
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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