Hi all,
I have a series of codes (e.g., NAC4, NAC5, NAC6) embedded in paragraphs (one paragraph per cell) that need to be updated with new codes (e.g., NAC4 needs to be replaced with NAC35). I'm using a "Substitute Multiple" formula, which seems to work when the codes end in single digits (e.g., NAC4 is converted to NAC35 without issue), but when the code ends in two or more digits, I get what appear to be a string of random numbers (e.g., NAC20 becomes NAC3430 instead of NAC51). I'm guessing the numbers are, in fact, not random, but Excel is substituting and then re-substituting as it progresses through the text. Is it possible to alter the formula so that this doesn't happen? For reference, here's the VBA code for the formula:
'Name function and dimension argument variables and declare their data types
Function SubstituteMultiple(text As String, old_text As Range, new_text As Range)
'Dimension variable and declare data type
Dim i As Single
'Iterate through cells in argument old_text
For i = 1 To old_text.Cells.Count
'Replace strings in value based on variable i
Result = Replace(text, old_text.Cells(i), new_text.Cells(i))
'Save manipulated value to variable text
text = Result
Next i
'Return value stored in variable Result to worksheet
SubstituteMultiple = Result
End Function
I have a series of codes (e.g., NAC4, NAC5, NAC6) embedded in paragraphs (one paragraph per cell) that need to be updated with new codes (e.g., NAC4 needs to be replaced with NAC35). I'm using a "Substitute Multiple" formula, which seems to work when the codes end in single digits (e.g., NAC4 is converted to NAC35 without issue), but when the code ends in two or more digits, I get what appear to be a string of random numbers (e.g., NAC20 becomes NAC3430 instead of NAC51). I'm guessing the numbers are, in fact, not random, but Excel is substituting and then re-substituting as it progresses through the text. Is it possible to alter the formula so that this doesn't happen? For reference, here's the VBA code for the formula:
'Name function and dimension argument variables and declare their data types
Function SubstituteMultiple(text As String, old_text As Range, new_text As Range)
'Dimension variable and declare data type
Dim i As Single
'Iterate through cells in argument old_text
For i = 1 To old_text.Cells.Count
'Replace strings in value based on variable i
Result = Replace(text, old_text.Cells(i), new_text.Cells(i))
'Save manipulated value to variable text
text = Result
Next i
'Return value stored in variable Result to worksheet
SubstituteMultiple = Result
End Function