Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub ReplaceMultipleCharacters()
- Dim ws As Worksheet
- Dim rng As Range
- Dim cell As Range
- Dim replacements As Object
- Dim oldText As Variant
- Dim newText As String
- ' Set the worksheet and range
- Set ws = ThisWorkbook.Sheets("Sheet1")
- Set rng = ws.Range("A1:A10") ' Adjust this range to your data
- ' Create a dictionary of replacements
- Set replacements = CreateObject("Scripting.Dictionary")
- replacements.Add "old_text1", "new_text1"
- replacements.Add "old_text2", "new_text2"
- replacements.Add "old_text3", "new_text3"
- ' Loop through the cells in the range
- For Each cell In rng
- If Not IsEmpty(cell) Then
- ' Loop through each key in the dictionary
- For Each oldText In replacements.Keys
- newText = Replace(cell.Value, oldText, replacements(oldText))
- cell.Value = newText
- Next oldText
- End If
- Next cell
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement