Share via

Ignoring message if text not found to replace

Anonymous
2023-03-21T09:51:36+00:00

Hi All,I have multiple words to replace in my sheet and below the code I am using to do it Sub ReplaceWords()
    Dim w As Worksheet
    Set w = Worksheets(Worksheets.Count)
    With w.Range("F:N")
          .Replace What:="DC", Replacement:="Delivery Chellan", LookAt:=xlPart, MatchCase:=False
        .Replace What:="Inv.", Replacement:="Invoice", LookAt:=xlPart, MatchCase:=True
        .Replace What:="OI", Replacement:="Other Items, LookAt:=xlPart, MatchCase:=False
    End With
End Sub

When the code runs, it will throw the message if any of the word in the code not exists in the excel sheet.

Could not find anything to replace

Is there any way to avoid this message?

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2023-03-21T10:50:12+00:00

Hi Nagul

I'm AnnaThomas and I'd happily help you with your question. In this Forum, we are Microsoft consumers just like yourself.

To avoid the message, add the following line of code at the beginning of your ReplaceWords() subroutine:

Application.DisplayAlerts = False

Then, add the following line of code at the end of your subroutine to turn the alerts back on:

Application.DisplayAlerts = True

I hope this helps ;-), let me know if this is contrary to what you need, I would still be helpful to answer more of your questions.

Best Regards,

AnnaThomas

Give back to the community. Help the next person with this problem by indicating whether this answer solved your problem. Click Yes or No at the bottom.

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2023-03-21T13:46:44+00:00

    Hi Anna,

    Thank you so much for the help.

    It works exactly as requested

    Was this answer helpful?

    0 comments No comments