How to replace multiple macros with one by creating two new subs

Waimea

Active Member
Joined
Jun 30, 2018
Messages
465
Office Version
  1. 365
Platform
  1. Windows
Hi, I am using macros to go between sheets and I have 20 separate macros for going to different sheets and I have an additional 20 sheets to go back to the home sheet.

I would like some help with how to create two macro/subroutines that replaces these 40 macros with two new macros.

The first macro should take sheet name, scroll area, and tab color as arguments. The second macro should take sheet name and tab color as arguments.

Code:
Sub StartOption1()
    ActiveWorkbook.worksheets("Option1").Visible = True
    ActiveWorkbook.worksheets("Home").Visible = False
    worksheets("Option1").Activate
    Sheets("Option1").ScrollArea = "C1:X37"
    Sheets("Option1").Tab.Color = RGB(182, 173, 165)
End Sub


Sub StarOption1Back()
    ActiveWorkbook.worksheets("Home").Visible = True
    ActiveWorkbook.worksheets("Option1").Visible = False
    worksheets("Home").Activate
    Sheets("Home").Tab.Color = RGB(182, 173, 165)   
End Sub
 
Hi Fluff,

works like a clock! Thank you very much!

It seems so simple when you write code!
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,213,534
Messages
6,114,186
Members
448,554
Latest member
Gleisner2

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