Results 1 to 6 of 6

Thread: [RESOLVED] Using a Cell value to select worksheet

  1. #1
    Lively Member
    Join Date
    Oct 08
    Posts
    88

    Resolved [RESOLVED] Using a Cell value to select worksheet

    Hello All,

    Been a while since I haunted you, hope all is well with you and yours!

    My question is this:

    Is there a code that will select a sheet based on the value of a worksheet cell or even better, a label caption? The cell or label number value is a known valid sheet number.

    For example:
    If I have a label in a Userform that is named "ReportNo" and the value in that label is "11-11-SR". I have a valid Worksheet named 11-11-SR. I need a code that will make that sheet the Activesheet based on the value of ReportNo.


    Kinda like this? Worksheets("Me.ReportNo").Select

    Thanks very much in advance!

    John

  2. #2
    PowerPoster
    Join Date
    Dec 04
    Posts
    18,587

    Re: Using a Cell value to select worksheet

    try
    vb Code:
    1. Worksheets(Me.ReportNo).Select
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    Lively Member
    Join Date
    Oct 08
    Posts
    88

    Re: Using a Cell value to select worksheet

    Thanks for the response!

    That still isn't working..I had tried that earlier too.

    Below is the code that I'm trying to get working. Be advised, I created a label in the same, Userform that the CB "End_Storm" resides (LbTest), for testing purposes and the default caption is "11-11-SR" (no quotations). I have confirmed that the Worksheet exists as when entered as Worksheets("11-11-SR").Select, the code works fine.

    Private Sub End_Storm_Click()
    Worksheets(Me.LbTest).Select
    Range("A1") = "test"
    MsgBox "Test"
    End Sub

    The error response is "Runtime error '13' Type mismatch.

    Thanks again for taking the time, I really do appreciate it!

    John

  4. #4
    Lively Member
    Join Date
    Oct 08
    Posts
    88

    Re: Using a Cell value to select worksheet

    Anyone on this?

  5. #5
    Super Moderator koolsid's Avatar
    Join Date
    Feb 05
    Location
    Mumbai, India
    Posts
    11,449

    Re: Using a Cell value to select worksheet

    Try this

    Worksheets(Trim(ReportNo.Caption)).Select

    I just tried it and it works....

    Sid
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  6. #6
    Lively Member
    Join Date
    Oct 08
    Posts
    88

    Re: Using a Cell value to select worksheet

    Koolsid....YOU are the man...that worked perfectly THANKS!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •