Test on sheets names

PaulS

Board Regular
Joined
Feb 26, 2006
Messages
66
To the experts:
I am looking for some VBA statements solving my problem:
I wrote a macro that produced a new worksheet with data selected data from a database worksheet. The macro does not expect more worksheets in the workbook. I recently found out that a user added more sheets for own use. This may cause the macro works on the wrong sheet.
I am looking for a small piece of VBA code as starter of my macro. It must perfom the following task:
• Test on one or more worksheets on the workbook – how do I get the number of sheets?
• If a sheet has the name “Database_yy-mm-dd” (=today) than make this the active sheet
• Ask the user sheet by sheet which contains the database.
• When question is answered with ‘yes’ then rename (or in case one sheet is found) that sheet to “Database_yy-mm-dd” (yy-mm-dd is today)
• Make the database sheet active so that the rest of the code will work on that sheet.
Normally I find the VBA code via the recording function, but I could not find a test on all worksheet names.
Thanks for your help.
Paul
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,214,821
Messages
6,121,762
Members
449,048
Latest member
excelknuckles

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