Thread: [Solved] VBA Swap text around
View Single Post
 
Old 11-27-2024, 02:01 AM
Shelley Lou Shelley Lou is offline Windows 10 Office 2016
Expert
 
Join Date: Dec 2020
Posts: 259
Shelley Lou is on a distinguished road
Default VBA Swap text around

Hi Macropod, thank you so much for providing the find and replace. I've put it into a little macro but for some reason it will only work if the text and number are separated by non breaking spaces and doesn't work if its just separated with a space - what do I need to add to include both space and non breaking space? Thanks

Code:
Sub SwapText_SchedulePart()
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
  .ClearFormatting
  .Forward = True
  .Wrap = wdFindStop
  .Format = True
  .MatchCase = False
  .MatchWildcards = True
  .text = "([Ss]chedule*)[, ]@([Pp]art*)([ ;.,])"
  .Replacement.text = "\2 of \1\3"
  .Execute Replace:=wdReplaceAll
End With
End Sub
Reply With Quote