Why does my macro keep crashing?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,
I have this macro that is supposed to delete the active sheet, select the welcome sheet and remove that sheets details from the sheet list in clumn Q to S

It works great then suddenly i get this message:
Run time error '-2147417848(8001010)
Automation error
The object invoked has disconnected from its clients

this is my code: if anyone can improve it and make it work without crashing this would be great

VBA Code:
Sub Delete()
Application.EnableEvents = False
Application.ScreenUpdating = False
 
WsName = ActiveSheet.Name
Sheets(WsName).Delete
Sheets("Welcome").Unprotect Password:="august"
Sheets("Welcome").Select
Sheets("Welcome").Columns("Q").Find(WsName, , xlValues, xlWhole, xlByRows, xlNext).Resize(, 3).ClearContents


Sheets("Welcome").Sort.SortFields.Clear
Sheets("Welcome").Sort.SortFields.Add2 Key:=Range( _
        "S11:S29"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortNormal
    With Sheets("Welcome").Sort
        .SetRange Range("Q11:S29")
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
 Sheets("Welcome").Sort.SortFields.Clear

  


  
  Sheets("Welcome").Protect Password:="august"
  

  Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub

Thanks

Tony
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
i don't think you should be able to delete the sheet you are on, better to select the next sheet and then delete so the focus works
 
Upvote 0

Forum statistics

Threads
1,215,028
Messages
6,122,749
Members
449,094
Latest member
dsharae57

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top