Results 1 to 6 of 6

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

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2008
    Posts
    89

    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 2004
    Posts
    25,618

    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

    Thread Starter
    Lively Member
    Join Date
    Oct 2008
    Posts
    89

    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

    Thread Starter
    Lively Member
    Join Date
    Oct 2008
    Posts
    89

    Re: Using a Cell value to select worksheet

    Anyone on this?

  5. #5
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Oct 2008
    Posts
    89

    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
  •  



Click Here to Expand Forum to Full Width