Macro with variable tab names

Will85

Board Regular
Joined
Apr 26, 2012
Messages
240
Office Version
  1. 365
Platform
  1. Windows
I have a a number of workbooks that each have 19 tabs. I have a macro that goes through each tab and hides some blank rows.

My current macro, as an example for one tab is as follows:

Sheets("1000").Select
ActiveSheet.Unprotect
ActiveSheet.Range("$A$1:$A$700").AutoFilter Field:=1, Criteria1:="1"
ActiveSheet.Protect

The sheet name "1000" is only applicable in one workbook, in another workbook the number scheme may change to "6001" as an example.

I would rather have my macro refer to a key to lookup the tab name, than actually hardcode the tab names in the macro.

For example, I have a tab called "Departments", and cells A1:A19 contain the department code that also corresponds to the tab names in each of the workbooks. I would prefer the macro pull the tab names from here, so that when I copy this workbook out I can change the "Departments" tab instead of the macro.

Thank you in advance for your help.
 
If you're using the code I supplied you should still be on the "Instructions" sheet.
Have you changed the code?
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,216,028
Messages
6,128,400
Members
449,448
Latest member
Andrew Slatter

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