I'm having issues getting a find/replace loop to work. I have a list of 122 values I want to easily find/replace, by saving a macro to my personal workbook. I'm trying to simplify it so that the values are each defined with a logical string name, then a find/replace increments up through the strings. Here's what I have:
Sub utf8_cleanup()
' reference: http://www.i18nqa.com/debug/utf8-debug.html
Dim find_prefix As String
Dim replace_prefix As String
Dim find_1 As String
Dim replace_1 As String
Dim find_2 As String
Dim replace_2 As String
Dim find_3 As String
Dim replace_3 As String
Dim replace_count As Integer
find_prefix = "find_"
replace_prefix = "replace_"
find_1 = "Â"
replace_1 = ""
find_2 = "–"
replace_2 = "–"
find_3 = "—"
replace_3 = "—"
' 122 of these pairs
replace_count = 1
Do Until replace_count = 122
find_value = find_prefix & replace_count
replace_value = replace_prefix & replace_count
Debug.Print "Finding " & find_value & "; replacing with " & replace_value
Cells.Replace What:=find_value, Replacement:=replace_value, LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, ReplaceFormat:=False
Debug.Print "Done " & replace_count & " replacement(s)"
replace_count = replace_count + 1
Loop
End Sub
The end result is the macro searching for the text of "find_value
" and "replace_value
", rather than the values of those strings (for example find_2
should translate to "Â
", or replace_2
translating to "-
"). I'm sure this is something stupidly simple--it's been months since I touched VBA.
Thanks in advance.