VBA IF cell in a specific sheet is equal to a number, the go to a specific sheet

nickthebizz

New Member
Joined
Jan 24, 2021
Messages
22
Office Version
  1. 2016
Platform
  1. Windows
Hi, my skills in VBA is at beginning level.

I have a sheet where I have my clients names written. I have made a button and I would like this button to take me to a specific sheet when each client is selected. I have manage to make a list where when i choose a client it returns a number in a cell starting from 1 and on in my clients sheet.

So if this number is equal to 1 I need the button to take me to a specific sheet which is for that specific client. If the cell is equal to 2 to another sheet etc.

Could anyone give me an insight please

thank you

Nik
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
We need specifics:
Like what is the name of the sheet with your button?
And you said:
So if this number is equal to 1 I need the button to take me to a specific sheet
so if number is 1 take me to what sheet?

Why not double click on "Alpha" to be taken to the sheet name "Alpha"
Would this not work?
What column on your sheet is these client names.
 
Upvote 0
1. Name of Sheet with Button is "Main".
2. If number is equal to 1 go to sheet "Shoretanks"
3. Client names is in sheet "Clients" where the number changes in cell A1 and names are in column B.

Reason I do not use links is is that I wish to work on this code to also add in a print with another button later on

thank you
 
Upvote 0
I do not see logic here:
You said:
If number is equal to 1 go to sheet "Shoretanks"
I do not see how 1 equals Shoretanks
 
Upvote 0
Try this:
VBA Code:
Private Sub CommandButton1_Click()
'Modified  3/19/2021  9:34:57 AM  EDT
On Error GoTo M
Dim ans As Long
ans = Range("A1").Value
Sheets("shoretanks" & ans).Activate
Exit Sub
M:
MsgBox "Sheet named" & vbNewLine & "shoretanks" & ans & vbNewLine & "Does not exist", , "Oops"
End Sub
 
Upvote 0
Solution
Works as I wanted! thank you.

One last question.

Can i make
ans = Range("A1").value

to reference to A1 in a different sheet where the button is.

Something like

ans = Sheets("Calculations").Range("A1").value

?
 
Upvote 0
Works as I wanted! thank you.

One last question.

Can i make
ans = Range("A1").value

to reference to A1 in a different sheet where the button is.

Something like

ans = Sheets("Calculations").Range("A1").value

?
So it looks like you have the solution
But I thought in post 3 you said button was in sheet named "Main:
Your quote in post 3
Name of Sheet with Button is "Main"

Or all you putting buttons in more then one sheet?

If so write code like this: ans=Activesheet.name
 
Upvote 0

Forum statistics

Threads
1,215,639
Messages
6,125,968
Members
449,276
Latest member
surendra75

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