Delete a sheet...VB

katie1071

Board Regular
Joined
Mar 17, 2003
Messages
120
Hi,

Need help with an IF statement in VB. I need to check if a Sheet has been deleted before switching to it and processing.

For example, a user could delete a worksheet called out in a macro. If so, the module will fail.

In the code, each sheet is called out by Sheet#.Select. I just want to verify it exists before moving forward.

Thanks,
Katie
 
Katie

Is this code being used on every worksheet?
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
In my workbook, there are 5 worksheets. Each worksheet is different and some link to each other. Before the user sends the file to an external client, they run this macro which strips out formulas, etc and each sheet has a different set of procedures to run. The user could delete a sheet if it's not needed. I want to be able to bypass a sheet if it's been deleted but not bypass other errors that may occur.
 
Upvote 0
Hi Katie

If you have tried the code you saw that you only had to Enable the error handler once and that it stayed enabled as you selected all the sheets. You can, if you want, disable it between selections

In this case you always have to enable it before you select each sheet.

Like blocks of


On Error Resume Next
Sheet6.Select
If Err.Number = 0 Then
Cells.Select
Selection.EntireColumn.Hidden = False
Else
Err.Clear
End If
On Error Goto 0


This way the code between the selections of the sheets will run as usual.

HTH
PGC
 
Upvote 0

Forum statistics

Threads
1,215,181
Messages
6,123,513
Members
449,101
Latest member
mgro123

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