+ Reply to Thread
Results 1 to 10 of 10

Thread: Display worksheet from Userform procedure

  1. #1
    Registered User
    Join Date
    07-13-2011
    Location
    Boston, MA USA
    MS-Off Ver
    Excel 2010
    Posts
    28

    Display worksheet from Userform procedure

    I'm learning VBA from books and the internet. Forgive me if this is really dumb question.

    I'm developing a VBA application consisting of numerous Userforms, and my data exists on several worksheets within the same workbook. In some cases, I want to navigate from a userform to a protected worksheet where the user can double-click to select some codes from a complex table. The user can return to the Userform by double-clicking a specfic cell and the selected codes from the worksheet are then processed in Userform procedures. Most of this works fine.
    My problem: I can't find a way to actually show the worksheet. In testing, I've hit Alt F11 to get to the worksheet. I use a command button on the Userform (frmSHLDRProc) and the following code to try to show a worksheet named Table15-5...
    Private Sub cmdTable15_5_Click()
    
    Application.Sheets("Table15-5").Activate
    
    Sheets("Table15-5").Protect Password:="xxxxx", userinterfaceonly:=True
    
    Range("A5") = txtDx_ID
    If txtDxClass >= 0 Then
        Range("B6") = txtDxClass
        Range("C6") = txtDxGrade
        Range("A3") = txtDxRow
        Range("J4") = txtSubDxDesc
        Range("D6") = txtSumDxImp
    Else
        Range("B6") = ""
        Range("C6") = ""
        Range("A3") = ""
        Range("J4") = ""
        Range("D6") = ""
    End If
    
    frmSHLDRProc.Hide
    
    Worksheets("Table15-5").Select
    
    End Sub
    Am I way off base? How do I show the worksheet. Returning to the Userform works fine.
    Thanks for any help.
    Last edited by bdoodle; 11-10-2011 at 05:35 PM.

  2. #2
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel 2007
    Posts
    825

    Re: How display worksheet from Userform procedure

    hi,
    not sure I got it but I use a UserForm and for navigate I use OptionButtons.
    it's just an idea...!
    Private Sub OptionButton1_Click()
    Sheets("As1").Visible = 1
    Sheets("As1").Activate
    TextBox1.Value = "something1"
    Sheets("As2").Visible = 0
    Sheets("Inf").Visible = 0
    With Me.ComboBox1 'this is my combobox
            .Clear
            .List = Application.Transpose(Worksheets("As1").Range("b12:b36"))
        End With
        End Sub
    and OptionButton2
    Private Sub OptionButton2_Click()
    Sheets("As2").Visible = 1
    Sheets("As2").Activate
    
    TextBox1.Value = "something2"
    Sheets("As1").Visible = 0
    Sheets("Inf").Visible = 0
    With Me.ComboBox1
            .Clear
            .List = Application.Transpose(Worksheets("As2").Range("b12:b36"))
        End With
    End Sub
    Regards, John

  3. #3
    Registered User
    Join Date
    07-13-2011
    Location
    Boston, MA USA
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: How display worksheet from Userform procedure

    Thanks, John.
    I noticed that you used the following statement that I didn't have:
    Sheets("As2").Visible = 1
    I added something comparable to my code for my particular sheet. It behaved no differently when I tested it.
    FYI, My command button works the SECOND time it is hit. ie. The first time I hit it, nothing happens so I hit alt F11 to get to the worksheet. I return to the Userform from the worksheet and then hit the command button again, and it works... it shows the worksheet.
    I'm still at a loss!

  4. #4
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel 2007
    Posts
    825

    Re: How display worksheet from Userform procedure

    when I hit optionbutton 1 I have Sheet As1 visible only (I am in) , Sheets As2 and Inf are not.
    when I hit optionbutton 2 I have Sheet As2 visible only (I am in) , Sheets As1 and Inf are not and so on.
    the optionbuttons are in UserForm. I use only one.
    Regards, John

  5. #5
    Registered User
    Join Date
    07-13-2011
    Location
    Boston, MA USA
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: How display worksheet from Userform procedure

    Thanks for sticking with me, John.
    I think I understand your use of option buttons, but...
    Did I make it clear that when I hit the command button the first time, it hides my Userform and I see VBA code... no worksheets?
    It's not that I see the wrong worksheet or too many worksheets. I see no worksheet! I'm reluctant to convert to using the option button, when the fundamental problem would not seem to be addressed by doing so. The code to make the sheet visible is not working.

  6. #6
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel 2007
    Posts
    825

    Re: How display worksheet from Userform procedure

    see if it helps you (updated) and try to modify for yr needs...
    Attached Files Attached Files
    Last edited by john55; 11-10-2011 at 04:43 PM.
    Regards, John

  7. #7
    Registered User
    Join Date
    07-13-2011
    Location
    Boston, MA USA
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: How display worksheet from Userform procedure

    Thanks for the sample. I'm sure I'll use something similar at some point for a similar need.
    But, bear with me one more time, John.
    You start by showing a worksheet and then showing a userform that you use to govern the visibility of each worksheet after that.
    I start with a splash screen that after 5 seconds shows a Userform. No worksheet is shown until I try to do so with my command button. How do I get that first worksheet to appear?

  8. #8
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel 2007
    Posts
    825

    Re: How display worksheet from Userform procedure

    try to check what code you have in
    Private Sub Workbook_Open()
    '   
    ' 'here is yr code
     ''''' for example you can see I use
             'ActiveWindow.DisplayHeadings = False
             'ActiveWindow.DisplayGridlines = False
            'Application.DisplayFullScreen = True
    '
    end sub
    I think the excel starts with the default sheet if you have nothing in the "Workbook_Open()"
    Regards, John

  9. #9
    Registered User
    Join Date
    07-13-2011
    Location
    Boston, MA USA
    MS-Off Ver
    Excel 2010
    Posts
    28

    Re: How display worksheet from Userform procedure

    thanks for all the help, John!

  10. #10
    Valued Forum Contributor john55's Avatar
    Join Date
    10-23-2010
    Location
    Europe
    MS-Off Ver
    Excel 2007
    Posts
    825

    Re: Display worksheet from Userform procedure

    k, you're welcome!
    Regards, John

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0