+ Reply to Thread
Results 1 to 5 of 5

Simple UserForm/Worksheet Hide/Unhide

Hybrid View

  1. #1
    Registered User
    Join Date
    01-04-2010
    Location
    Oak Harbor, Washington
    MS-Off Ver
    Excel 2003
    Posts
    15

    Simple UserForm/Worksheet Hide/Unhide

    Okay, this is probably a lot simpler than I'm thinking. Only problem is, I'm new to programming userforms, so I'll need help along the way.

    I have 2 worksheets set up, one that's just a blank worksheet with a button on it that pops up my UserForm. The other worksheet has all the current data on it and is hidden and protected.

    One of the buttons on the UserForm I want to use to hide the userform, unhide and view the main worksheet, but not make changes except for autofiltering and sorting(sorting is another issue altogether). Then I want to make a macro on cell select that hides that worksheet and brings the UserForm back up.

    Is this possible?

    PS. On a side note: When I protect the worksheet, it won't let me sort the data even though I have 'Sort' selected as an allowed action. Any way around this?

  2. #2
    Valued Forum Contributor blane245's Avatar
    Join Date
    02-20-2009
    Location
    Melbourne, FL
    MS-Off Ver
    Excel 2010
    Posts
    649

    Re: Simple UserForm/Worksheet Hide/Unhide

    Rather than dropping out of the VBA environment, why don't you let the VBA environment control the autofilter and sorting functions? That might be a little smoother GUI. You can always hide and show the spreadsheet from VBA so that the user can see when necessary.

  3. #3
    Registered User
    Join Date
    01-04-2010
    Location
    Oak Harbor, Washington
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Simple UserForm/Worksheet Hide/Unhide

    That's an interesting idea. I also ran into another problem when I started experimenting with data entry and found out that I can't use the VBA to enter data into a protected sheet. Is there also a way around that?

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

    Re: Simple UserForm/Worksheet Hide/Unhide

    You need to unprotect the sheet first
    Sheet1.Unprotect "your password"
    'your code
    Sheet1.Protect "your password"
    Hope that helps.

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

    Free DataBaseForm example

  5. #5
    Registered User
    Join Date
    01-04-2010
    Location
    Oak Harbor, Washington
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Simple UserForm/Worksheet Hide/Unhide

    Quote Originally Posted by royUK View Post
    You need to unprotect the sheet first
    Sheet1.Unprotect "your password"
    'your code
    Sheet1.Protect "your password"
    I tried this and got the same thing. Here's the code I used. Name was still Sheet1, but I don't yet have a password to unprotect it yet since right now I'm just trying to get it to work.

    Private Sub cmdSubmit1_Click()
    
    Dim iRow As Long
    Dim ws As Worksheet
    Set ws = Worksheets("MAIN")
    
    'find first empty row in database
    iRow = ws.Cells(Rows.Count, 1) _
      .End(xlUp).Offset(1, 0).Row
      
    'check for a name
    If Trim(Me.txtName1.Value) = "" Then
      Me.txtName1.SetFocus
      MsgBox "Please enter member's name"
      Exit Sub
    End If
    
    Sheet1.Unprotect ""
    
    'copy data to database
    ws.Cells(iRow, 1).Value = Me.txtRate1.Value
    ws.Cells(iRow, 2).Value = Me.txtName1.Value
    ws.Cells(iRow, 3).Value = Me.txtDivision1.Value
    ws.Cells(iRow, 4).Value = Me.txtRcvd1.Value
    ws.Cells(iRow, 5).Value = Me.txtLoss1.Value
    
    Sheet1.Protect ""
    
    
    'clear the data
    Me.txtName1.Value = ""
    Me.txtRate1.Value = ""
    Me.txtDivision1.Value = ""
    Me.txtRcvd1.Value = ""
    Me.txtLoss1.Value = ""
    Me.txtName1.SetFocus
    
    End Sub

+ 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