+ Reply to Thread
Results 1 to 2 of 2

how to use textbox to activate worksheets?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-04-2010
    Location
    singapore
    MS-Off Ver
    Excel 2007
    Posts
    143

    how to use textbox to activate worksheets?

    Hi,

    i am currently dealing with an excel with more than 90 sheets. Hence i am trying to write a macro for users to go to the sheet they want from the main page. I have thought of using a textbox and a macro.

    private sub commandbutton1_click()
    
    rname = TextBox1.Text
    if rname="",Then GoTo ErrHandler :
    On Error GoTo Errhandler:
    
    If rname = "sheet1" Then
    worksheets("sheet1").Activate
    
    Else
    If rname = "sheet2" Then
    worksheets("sheet2").Activate
    
    Else 
    If (continues to the last sheet, >90 sheets)
    
    End If
    End If
    End If
    ....
    
    GoTo Lastline
    
    ErrHandler: 
    MsgBox ("Invalid name, please try again")
    
    Lastline:
    
    End Sub
    This is very troublesome, hence i am hoping if any1 knows a shorter/easier coding.something similar to the code below

    private sub commandbutton_click()
    rname=textbox1.text
    if rname = ""then GoTo ErrHandler:
    On Error GoTo ErrHandler:
    
    worksheets("rname").Activate
    
    GoTo Lastline:
    
    ErrHandler: 
    MsgBox ("Invalid name, please try again")
    
    Lastline:
    
    End Sub
    Thank you

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: how to use textbox to activate worksheets?

    See the suggestions here
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1