excel crashes after deleting a sheet with macro

mdd16

Board Regular
Joined
Jan 11, 2011
Messages
84
Office Version
  1. 365
Platform
  1. Windows
Hello there,

I am facing problem with excel crashing when I delete two sheets using macro as follows :

All I want to do is to delete two sheets named KrSh_H and UvArg_H and make fresh copies of two other sheets and name them same as deleted sheets.

I start with a sheet called "1Rx1" and refer to that name as Sheet(Arg). After deleting these two sheets I need to go to "1Rx1" and make a new copy of it with name "UvArg_H"

Similarly I need to delete the sheet 'KrSh_H' and make a copy of another sheet called 'KrSh_H_Templ' and then rename the new copy as 'KrSh_H'

But excel crashes every time.

Please help with code below


Sub Create_H_Sheets()


Dim ThSh


Arg = ActiveSheet.Name


Application.DisplayAlerts = False


ActiveWorkbook.Sheets("KrSh_H").Delete
ActiveWorkbook.Sheets("UvArg_H").Selec
ActiveSheet.Shapes("Btn1").Delete
ActiveSheet.Shapes("Btn2").Delete
ActiveWorkbook.Sheets("UvArg_H").Delete


ActiveWorkbook.Sheets("KrSh_H _Templ").Visible = True
ActiveWorkbook.Sheets(Arg).Select


Sheets(Arg).Copy after:=Sheets("KrSh_H _Templ")
ActiveSheet.Name = "UvArg_H"


ActiveWorkbook.Sheets("KrSh_H_Templ").Select
ActiveSheet.Copy after:=ActiveWorkbook.Sheets("KrSh_H_Templ")
ActiveSheet.Name = "KrSh_H"
ActiveWorkbook.Sheets("KrSh_H_Templ").Visible = False
Application.DisplayAlerts = True


End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,214,589
Messages
6,120,416
Members
448,960
Latest member
AKSMITH

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