excel crashes after deleting a sheet with macro

mdd16

New Member
Joined
Jan 11, 2011
Messages
11
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
 

Some videos you may like

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Watch MrExcel Video

Forum statistics

Threads
1,122,312
Messages
5,595,427
Members
413,990
Latest member
Kher83

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
Top