Hi @Chris K,
I have tested your VBA script in several devices, and I confirm that your VBA makes Find Replace not working properly. The reason is your VBA uses Range.Replace, which save key search settings (like LookAt, SearchOrder, etc.) whenever you run it. Since Excel remembers Replace settings globally, those saved settings are shared with the regular Find/Replace dialog which can cause it behaving differently.
About your syntax error, that's because you are having a -------------------------------- line with wrong syntax. If you want to add a line to distinguish script parts, you need to use '---------------------------- instead.
To make your script and Find Replace both work properly, you need to reset the Find/Replace state after your macro. You can try this script:
Sub ReplaceAcronymns()
Dim rng As Range
Dim cel As Range
Set rng = Selection
ResetFindReplaceState
With rng
.Replace What:="(", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByColumns, _
MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
.Replace What:=")", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByColumns, _
MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
.Replace What:=",", Replacement:=" ,", LookAt:=xlPart, SearchOrder:=xlByColumns, _
MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
.Replace What:=". ", Replacement:=vbLf & ". ", LookAt:=xlPart, SearchOrder:=xlByColumns, _
MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
End With
With rng
.Replace What:="IMCA", Replacement:="Independent Mental Capacity Assessment", LookAt:=xlPart, _
SearchOrder:=xlByColumns, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
.Replace What:=" HART", Replacement:=" Homecare and Reablement Team", LookAt:=xlPart, _
SearchOrder:=xlByColumns, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
' ...repeat same pattern for your other replacements...
End With
With rng
.Replace What:=" ,", Replacement:=",", LookAt:=xlPart, SearchOrder:=xlByColumns, _
MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
.Replace What:=vbLf & vbLf, Replacement:=vbLf, LookAt:=xlPart, SearchOrder:=xlByColumns, _
MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
End With
rng.CheckSpelling
For Each cel In rng
On Error Resume Next
cel.Characters(Start:=1, Length:=0).Font.FontStyle = "Regular"
cel.Characters(Start:=1, Length:=InStr(1, cel.Value, ":", vbTextCompare)).Font.FontStyle = "Bold"
On Error GoTo 0
Next cel
ResetFindReplaceState ' leave Excel in a safe Find/Replace state
End Sub
Private Sub ResetFindReplaceState()
' Clear any format constraints used by Find/Replace
Application.FindFormat.Clear
Application.ReplaceFormat.Clear
' Force Excel to re-store "safe" search settings
On Error Resume Next
Cells.Find What:="", After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, _
MatchByte:=False, SearchFormat:=False
Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows, _
MatchCase:=False, MatchByte:=False, SearchFormat:=False, ReplaceFormat:=False
On Error GoTo 0
End Sub
I hope this helps you move forward smoothly. If you have any questions or need further assistance, please feel free to share them in the comments on this post so I can continue to support you.
Thank you for your patience and understanding. Looking forward to your response.