VBA to Check if Worksheet Exists in A Workbook

juan4412

Board Regular
Joined
Oct 17, 2011
Messages
94
I have an array that opens a workbook containing close to 100 worksheets, and copies specific sheet names into there own individual workbooks. The problem I have now, is that I assume the worksheet exists in the workbook, but often times it does not :( Is there a way to add some sort of "catch" that will 1st verify the worksheet exists instead of my code crashing?
 
Tusharm --- that will work for copying the sheets, but where in the code does it check to see if the worksheet exists?
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
The WS is nothing bit.

Run the code and you will see it works correctly -- if I understood your other requirements correctly. ;)
Tusharm --- that will work for copying the sheets, but where in the code does it check to see if the worksheet exists?
 
Upvote 0
Well, I'll be!! You were exactly right, it did execute as I was needing.

Can I throw one more stipulation into the code requirements....How would I remove highlighting (if there is any) from the worksheets in the array?
 
Upvote 0
The code I posted also works, much in the same way as Tushar's does - it checks for a worksheet in a specific workbook.

I used a function because that's what was used in the code earlier.

Personally I would use the Select Case method, or something similar, to do this

I believe somebody posted the code for that earlier.

It's much shorter and more compact.
 
Upvote 0

Forum statistics

Threads
1,216,134
Messages
6,129,070
Members
449,485
Latest member
greggy

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