Advertisement
Guest User

Untitled

a guest
Mar 21st, 2025
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. Sub ReplaceMultipleCharacters()
  2. Dim ws As Worksheet
  3. Dim rng As Range
  4. Dim cell As Range
  5. Dim replacements As Object
  6. Dim oldText As Variant
  7. Dim newText As String
  8.  
  9. ' Set the worksheet and range
  10. Set ws = ThisWorkbook.Sheets("Sheet1")
  11. Set rng = ws.Range("A1:A10") ' Adjust this range to your data
  12.  
  13. ' Create a dictionary of replacements
  14. Set replacements = CreateObject("Scripting.Dictionary")
  15. replacements.Add "old_text1", "new_text1"
  16. replacements.Add "old_text2", "new_text2"
  17. replacements.Add "old_text3", "new_text3"
  18.  
  19. ' Loop through the cells in the range
  20. For Each cell In rng
  21. If Not IsEmpty(cell) Then
  22. ' Loop through each key in the dictionary
  23. For Each oldText In replacements.Keys
  24. newText = Replace(cell.Value, oldText, replacements(oldText))
  25. cell.Value = newText
  26. Next oldText
  27. End If
  28. Next cell
  29. End Sub
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement