+ Reply to Thread
Results 1 to 6 of 6

Allow Cell Formatting in a userform

Hybrid View

  1. #1
    Registered User
    Join Date
    01-26-2014
    Location
    South Africa
    MS-Off Ver
    Excel 365 (latest version)
    Posts
    29

    Allow Cell Formatting in a userform

    Good morning/afternoon/evening

    I would like to ask you kind people for a little more help. I have created a userform to password protect/unprotect all worksheets at once with help from this forum. What i would like is to activate the check box so that if i would like to allow cell formatting i can. See image below. Another thing if possible, is when i input the password, is there a way a popup can appear to confirm password. This is what i have so far....


    Private Sub CheckBox4_Click()
    
    End Sub
    
    Private Sub cmdCancel_Click()
    Unload Me
    End Sub
    
    Private Sub cmdProtect_Click()
    Dim wSheet As Worksheet
        On Error Resume Next
        For Each wSheet In Worksheets
            If wSheet.ProtectContents = True Then
                wSheet.Unprotect Password:=txtPwd.Text
        Else
                wSheet.Protect Password:=txtPwd.Text, _
                    AllowFormattingCells:=CheckBox4.Enabled
            End If
        Next wSheet
        If Err <> 0 Then
            MsgBox "You have entered an incorrect password. All worksheets could not " & _
            "be unprotected.", vbCritical, "Incorrect Password"
            End If
        On Error GoTo 0
        Unload Me
    End Sub
    
    Private Sub Label5_Click()
    
    End Sub
    
    Private Sub txtPwd_Change()
    
    End Sub
    
    Private Sub UserForm_Click()
    
    End Sub
    Your help or suggestions would be appreciated greatly
    Attached Images Attached Images
    Last edited by pkool; 09-01-2017 at 10:23 AM.

  2. #2
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Allow Cell Formatting in a userform

    To allow formatting if the checkbox is checked, ad the following code after the Dim wSheet as Worksheet line of the code you posted above..
    If CheckBox4 = True Then
    ActiveSheet.Protect AllowFormattingCells:=True
    MsgBox "Cells can now be formatted"
    Else
    ActiveSheet.Protect AllowFormattingCells:=False
    End If
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

  3. #3
    Registered User
    Join Date
    01-26-2014
    Location
    South Africa
    MS-Off Ver
    Excel 365 (latest version)
    Posts
    29

    Re: Allow Cell Formatting in a userform

    Hi gmr4evr1

    I added the code but it still allows all worksheets to allow formatting, whether or not it has been checked. Is there something i am missing. This is what i have done
    Private Sub CheckBox4_Click()
    
    End Sub
    
    Private Sub cmdCancel_Click()
    Unload Me
    End Sub
    
    Private Sub cmdProtect_Click()
    Dim wSheet As Worksheet
    If CheckBox4 = True Then
    ActiveSheet.Protect AllowFormattingCells:=True
    MsgBox "Cells can now be formatted"
    Else
    ActiveSheet.Protect AllowFormattingCells:=False
    End If
        On Error Resume Next
        For Each wSheet In Worksheets
            If wSheet.ProtectContents = True Then
                wSheet.Unprotect Password:=txtPwd.Text
        Else
                wSheet.Protect Password:=txtPwd.Text, _
                    AllowFormattingCells:=CheckBox4.Enabled
            End If
        Next wSheet
        If Err <> 0 Then
            MsgBox "You have entered an incorrect password. All worksheets could not " & _
            "be unprotected.", vbCritical, "Incorrect Password"
            End If
        On Error GoTo 0
        Unload Me
    End Sub
    
    Private Sub Label5_Click()
    
    End Sub
    
    Private Sub txtPwd_Change()
    
    End Sub
    
    Private Sub UserForm_Click()
    
    End Sub

  4. #4
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Allow Cell Formatting in a userform

    Can you attach a sample workbook with your userform and code please? I'm trying to make a mock-up of what you have and things aren't making sense to be when I do. I'd rather work with the real thing so I can do a better job of helping you out. The code I provided should only work on the active sheet if the checkbox is checked and with my mock-up, I'm getting the same results as you are.

  5. #5
    Registered User
    Join Date
    01-26-2014
    Location
    South Africa
    MS-Off Ver
    Excel 365 (latest version)
    Posts
    29

    Re: Allow Cell Formatting in a userform

    Hi there

    Please see fle attached, thanks for your help bud!!! Sorry for delay, had to delete sheet to make it smaller
    Attached Files Attached Files

  6. #6
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Allow Cell Formatting in a userform

    pkool,
    Just wanted to let you know I haven't forgotten about you. I was on vacation last week and was just now able to take a look at your workbook. The only thing I've noticed is that there is 1 or 2 lines that might be creating the problem you are having.
    Here is the code with those 2 lines commented out...
    Private Sub cmdCancel_Click()
    Unload Me
    End Sub
    
    Private Sub cmdProtect_Click()
    Dim wSheet As Worksheet
    If CheckBox4 = True Then
    ActiveSheet.Protect AllowFormattingCells:=True
    MsgBox "Cells can now be formatted"
    'Else
    'ActiveSheet.Protect AllowFormattingCells:=False
    End If
        On Error Resume Next
        For Each wSheet In Worksheets
            If wSheet.ProtectContents = True Then
                wSheet.Unprotect Password:=txtPwd.Text
        Else
                wSheet.Protect Password:=txtPwd.Text
                    'AllowFormattingCells:=CheckBox4.Enabled
            End If
        Next wSheet
        If Err <> 0 Then
            MsgBox "You have entered an incorrect password. All worksheets could not " & _
            "be unprotected.", vbCritical, "Incorrect Password"
            End If
        On Error GoTo 0
        Unload Me
    End Sub
    The problem is that the Checkbox code I provided will only work on the sheet that is active when the code runs.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Conditional Formatting using a userform.
    By liamfrancis2013 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-09-2016, 07:40 AM
  2. [SOLVED] Userform Launch - show userform when any cell in range on any worksheet is double clicked
    By Armitage2k in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-27-2016, 03:38 AM
  3. Conditional Formatting - Can it be passed to a cell in a sheet from a Userform?
    By JJFletcher in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-17-2014, 05:58 PM
  4. [SOLVED] Userform TextBox Problem... formatting code clears data instead of formatting
    By michaeljoeyeager in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-26-2012, 11:00 AM
  5. Formatting Combobox in Userform
    By Mordred in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-11-2011, 03:00 AM
  6. Userform Textbox Formatting
    By lilsnoop in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 03-02-2009, 02:53 PM
  7. [SOLVED] Userform formatting
    By Trefor in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-18-2006, 12:20 AM

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.6.0 RC 1