Finding and deleting a certain word I have a working macro that finds a specific word and deletes the whole text. It finds the word "JOBSPECIALTYCODE" in the sheet, selects and deletes it, then moves to the next sheet. I just want to ask if there is any alternative way to make my macro work fast. I only use a record macro.



Sub aHaveProgess()
'
'
'
'

'Deleting Trash Text to make it clear

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
    .Text = "JOBSPECIALTYCODE"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchByte = False
    .CorrectHangulEndings = False
    .HanjaPhoneticHangul = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False
    .MatchWildcards = False
    .MatchFuzzy = False
End With

Do While Selection.Find.Execute
    Selection.SelectCell
    Selection.Delete Unit:=wdCharacter, Count:=1
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
Loop
End Sub
ScreenUpdating

In order for you to interact with a spreadsheet (e.g. moving the mouse, selecting a cell) , the display on your monitor is re-drawn something like 30+ times per second. This takes a lot of processing power.

If you set Application.ScreenUpdating = False then, while it is false, the screen will not be updated, and your code will run much faster.

Crucially though, make sure it is set back to True before your code ends. Else your code will finish running, but your user will think that Excel has frozen because the screen won't respond to their mouse. 

Make sure that before any End/Exit statements, or if errors are thrown, that you change the setting back.

Like so:

Public Sub DoThing()

    Application.ScreenUpdating = False

    On Error Goto CleanFail

    ...

    ...

    Code

    ...

    ...

CleanExit:

    Application.ScreenUpdating = True

    Exit Sub

CleanFail:

    On Error Goto 0

    '/ Handle errors here

    Resume CleanExit

End Sub


And now, assuming you put some kind of error handling in, your sub will always exit through CleanExit, which will always reset ScreenUpdating back to normal.