Hello!
I am currently trying to find a Macro that can be used to find and replace multiple values in one cell (the cell content and location can change). I am a complete novice, and am really not sure what I am doing!
I have Sheet1 that contains the following information:
A B
1 This is
2 The text
3 I would like to be copied
4 Into my workbook
-
50 in full
In another sheet in the workbook (which is re-named frequently) I have cells with multiple numerical values which correspond to the text in cell B. E.g. in G4 I will have: 1, 2, 3, 50
I would like to run a macro which looks up the numbers in selected cell(s), and replaces it with the text. So:
I am currently trying to find a Macro that can be used to find and replace multiple values in one cell (the cell content and location can change). I am a complete novice, and am really not sure what I am doing!
I have Sheet1 that contains the following information:
A B
1 This is
2 The text
3 I would like to be copied
4 Into my workbook
-
50 in full
In another sheet in the workbook (which is re-named frequently) I have cells with multiple numerical values which correspond to the text in cell B. E.g. in G4 I will have: 1, 2, 3, 50
I would like to run a macro which looks up the numbers in selected cell(s), and replaces it with the text. So:
1, 2, 3, 50 should become: This is, The text, I would like to be copied, in full
I currently have VBA code that successfully finds and replaces the values, but only up to 9. Then it starts replacing only part of double digits (10, 11 etc.) I know that this is due to:
Dim Rng As Range
Dim InputRng As Range, ReplaceRng As Range
xTitleId = "iThoughts"
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, LookAt:=xlPart
Next
Application.ScreenUpdating = True
End Sub
I am not sure how to change the code to allow it to find and replace numbers past 9... if there is anyway anyone could help, that would be great!
Thank you in advance!
I currently have VBA code that successfully finds and replaces the values, but only up to 9. Then it starts replacing only part of double digits (10, 11 etc.) I know that this is due to:
LookAt:=xlPart in the VBA but when changed to
xlwhole, it does not work at all.
Dim Rng As Range
Dim InputRng As Range, ReplaceRng As Range
xTitleId = "iThoughts"
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, LookAt:=xlPart
Next
Application.ScreenUpdating = True
End Sub
I am not sure how to change the code to allow it to find and replace numbers past 9... if there is anyway anyone could help, that would be great!
Thank you in advance!