Select Variable sheet name

whcmelvin

Board Regular
Joined
Jul 27, 2011
Messages
82
Hi this is my code. I want to select the sheet name that is the same as the login name. Each login name will have a sheet of its own.
i tried this code and i have error on Sheets(Variable).Select

Email = Sheets("Trading Platform").LoginName.Value
Variable = Email
MsgBox Email
Sheets(Variable).Select
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Assuming Email is a variable, then you can use that directly:

Code:
Sheets(Email).Select

Do make sure that sheet Email is actually in the Active workbook and not another that you have open.
 
Upvote 0
Hi, I'm a bit confused as to what you mean by login name. I'm going to assume that you don't mean their windows\network logon and that you have a named range somewhere which stores a "logon" name/id.

If that is the case then this should work.

Code:
Sub login()
    On Error Resume Next
    dim sheetName as String
    sheetName = Range("LoginName")
    With Sheets(sheetName)
        .Visible = True
        .Select
    End With
End Sub
 
Upvote 0
My excel sheet have a login function to allow user to login. so the excel have it own user. the login id is suppose to be thier email account. and every user should have a sheet name assign to them that will be named after their email.
 
Upvote 0
I have tried that code but it cant work. it gave me an error msg "Run-time error "9" Subscript out of range"
 
Upvote 0
So what value are you using to select the sheet when you get the error? Is there a sheet in the activeworkbook with this name?
 
Upvote 0
I have tried that code but it cant work. it gave me an error msg "Run-time error "9" Subscript out of range"

That's telling you there is no sheet in the Activeworkbook with the name held in the variable. How many workbooks do you have open, which is active and which contains the sheet that you want to open?
 
Upvote 0
So does the sheet exist in the workbook when you try and select the sheet? Or do you want the code to automatically create a new worksheet if it doesn't already exist?
 
Upvote 0

Forum statistics

Threads
1,224,582
Messages
6,179,670
Members
452,936
Latest member
anamikabhargaw

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