JerryMason
New Member
- Joined
- Jun 2, 2022
- Messages
- 7
- Office Version
- 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.
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.
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.
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.
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.
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.
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.