Using a button to select a macro to go to a sheet

aldino

New Member
Joined
Nov 20, 2005
Messages
7
Hi

Basically i need to have 2 buttons on a contents page, that will go to sheet 2, and 3 when clicked.

I have tried assigning

Sub Sheet2()
Sheets("Sheet2").Select
End Sub

to a button, but then when i press the button always an error comes up!

does the first line have to be Sub Button1_Click()?

Im not sure how to save it in VBA

What exactly should the code be?

Thanks.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

iggydarsa

Well-known Member
Joined
Jun 28, 2005
Messages
1,751
Office Version
  1. 2019
Platform
  1. Windows
the name depends on your button's name (in this case "Button1" I suppose)

then it should start with: Sub Button1_Click()
 
Upvote 0

WillR

Well-known Member
Joined
Feb 18, 2002
Messages
1,143
What sort of button are you using ?

There are two main types,

A forms button You can right click these & assign a macro from a normal module

A controls button - you need to code this in the relevant sheet code module
 
Upvote 0

Forum statistics

Threads
1,195,594
Messages
6,010,627
Members
441,558
Latest member
lambierules

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
Top