Macro with variable tab names

Will85

Active Member
Joined
Apr 26, 2012
Messages
254
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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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