Multiple Find and Replace Using a List of Old Values with New Values

JerryMason

New Member
Joined
Jun 2, 2022
Messages
7
Office Version
  1. 365
Hey guys.

I'm new with VBA and need to replace different values in my dataset with specific new values.
For instance, in Sheet1 I have values like $5.00M and need to turn that into $5,000,000. So, I dedcued I could search for ".00M" and replace it with Six Zeroes "000000", the result will be 5,000,000.
dataset.JPG

But as you can imagine, I have 100 variations of that from .00M to .99M and want to create a Macro that just handles a predefined list of the values in one shot.
find-replace.JPG


I found this macro template which is the closest but I'm confused as to how it handles it exactly. When you press Start, it asks you to define the "OLD" value range, then you select the "NEW" value range.
VBA Code:
Sub Replace_MultiValues()
Dim R As Range
Dim InputR As Range, ReplaceR As Range
xTitleId = "Choose Range"
Set InputR = Application.Selection
Set InputR = Application.InputBox("Old ", xTitleId, InputR.Address, Type:=8)
Set ReplaceR = Application.InputBox("New :", xTitleId, Type:=8)
Application.ScreenUpdating = False
For Each R In ReplaceR.Columns(1).Cells
    InputR.Replace What:=R.Value, Replacement:=R.Offset(0, 1).Value
Next
Application.ScreenUpdating = True
End Sub

Except that didn't work for me.
So, can someone tell me how I can customize the above code to
1. Take the OLD values in SHEET2 column A
2. Replace the OLD values with the "NEW" value (which is in the adjacent cell in Sheet2:Column B) in:
3. The dataset in the entirety of Sheet1

Thanks in advance.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Book2
ABCDEFGHIJKLMN
117.55M24.8M52.22M24.62M66.36M84.4M175500002480000052220000246200006636000084400000
222.03M57.47M9.69M45.37M14.89M93.79M22030000574700009690000453700001489000093790000
390.52M7.25M56.53M66.83M29.86M25.38M90520000725000056530000668300002986000025380000
416.71M32.43M68.68M61.17M85.39M9.04M16710000324300006868000061170000853900009040000
55.87M46.66M66.78M17.4M5.49M86.61M5870000466600006678000017400000549000086610000
682.41M63.24M48.17M92.64M55.51M98.16M824100006324000048170000926400005551000098160000
785.91M89.84M50.97M72.78M61.19M9.87M85910000898400005097000072780000611900009870000
88.28M41.11M37.18M27.32M52.38M65.85M82800004111000037180000273200005238000065850000
946.06M89.69M89.52M58.75M56.13M30.23M460600008969000089520000587500005613000030230000
1039.8M45.55M17.88M46.97M91.18M47M398000004555000017880000469700009118000047000000
1174.93M84.81M93.83M44.62M53.13M55.28M749300008481000093830000446200005313000055280000
1241.98M32.35M97.63M30.54M87.04M86.8M419800003235000097630000305400008704000086800000
1373.83M29.25M3.62M57.2M12.13M24.06M73830000292500003620000572000001213000024060000
1410.81M89.29M90.33M99.34M6.66M57.64M10810000892900009033000099340000666000057640000
1537.53M63.28M30.06M82.31M31.1M26.27M375300006328000030060000823100003110000026270000
169.13M46.87M35M78.14M14.89M78.75M91300004687000035000000781400001489000078750000
1747.71M63.53M6.06M71.3M55.54M70.59M47710000635300006060000713000005554000070590000
1826.8M22.32M75.71M53.11M5.68M91.92M26800000223200007571000053110000568000091920000
1914.82M81.37M35.48M62.53M92.73M95.66M148200008137000035480000625300009273000095660000
2084.24M30.42M94.42M77.21M9.66M36.17M84240000304200009442000077210000966000036170000
21
Sheet4
Cell Formulas
RangeFormula
H1:M20H1=LEFT(A1:F20, LEN(A1:F20)-1)*1000000
Dynamic array formulas.
 
Upvote 0
If you want to stick with a vba approach, what about doing them all at once?

VBA Code:
Sub Replace_MultiValues_v2()
  Dim R As Range
  Dim InputR As Range, ReplaceR As Range
  Const xTitleId As String = "Choose Range"
  
  Set InputR = Application.Selection
  Set InputR = Application.InputBox("Old ", xTitleId, InputR.Address, Type:=8)
  Set ReplaceR = Application.InputBox("New (Top-left cell):", xTitleId, Type:=8)
  With InputR
    ReplaceR.Resize(.Rows.Count, .Columns.Count).Value = Evaluate("substitute(" & .Address & ",""M"","""")*10^6")
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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