Protected sheet disables macro buttons

warda11

New Member
Joined
Feb 29, 2024
Messages
5
Office Version
  1. 365
Platform
  1. Windows
I am working on an Excel form to allow users to submit data about decisions made and topics covered in meetings as part of a larger project. I will have a lot of different people entering data in this Excel file, so I want to lock as many cells as I can to make sure things aren't accidentally deleted, and users can only type in the cells that correspond to the form. I have three buttons on this form; "Submit Decision", "Save, and "Reset". I successfully protected the workbook upon opening using this code:

Private Sub Workbook_Open()

Dim frm As Worksheet

Set frm = ThisWorkbook.Sheets("Form")

With frm

.Range("I6:L6").Locked = False
.Range("I8:L11").Locked = False
.Range("I13:L13").Locked = False
.Range("I15:L15").Locked = False
.Range("I24:L27").Locked = False
.Range("I29:L32").Locked = False
.Range("I34:L37").Locked = False
.Range("I39:L39").Locked = False
.Protect UserInterfaceOnly:=True
End With
End Sub

But now my issue is that the buttons don't allow you to click on them. I've tried unprotecting the cells behind the buttons (.Range("K17:L17"), .Range("J41:L41")), but this doesn't work. Is there something I'm missing to allow these buttons to be clicked but still protect the rest of the worksheet? And, while I'm at it, is there a way to lock the size of the buttons so users can't shrink them accidentally? (This is a problem I ran into when allowing a few test users access to the file....). I have included the code for the three buttons below. Thanks in advance!

Private Sub cmbDecision1_Click()

Dim msgValue As VbMsgBoxResult

msgValue = MsgBox("Do you want to save this decision?", vbYesNo + vbQuestion, "SubmitDecision")

If msgValue = vbYes Then

Call SubmitDecision

End If


End Sub

Private Sub cmdReset_Click()

Dim msgValue As VbMsgBoxResult

msgValue = MsgBox("Do you want to reset the form?", vbYesNo + vbQuestion, "Reset")

If msgValue = vbYes Then

Call Reset

End If

End Sub

Private Sub cmdSave_Click()

If Validate = True Then

Dim msgValue As VbMsgBoxResult

msgValue = MsgBox("Do you want to save the status report?", vbYesNo + vbQuestion, "Save")

If msgValue = vbYes Then

Call Save
Call Reset

End If

End If


End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Edit: I commented out all the code that unlocks specific cells to make sure the buttons still work, and they don't. When you click on a button (in design mode or not), it just allows you to change the size of the button but does not run the macro behind it. This is my first time working in Excel VBA and I am stumped!! Any help is greatly appreciated.
 
Upvote 0
Welcome to Mr Excel,

In your code you refer to Call SubmitDecision but you haven't shown that code.

Please use the code tags in the toolbar as it makes it easier for others to read your code.

Added note what code is behind Call Save & Reset?
 
Upvote 0
Here is the Call SubmitDecision, Save, and Reset code

VBA Code:
Sub Reset()
    With Sheets("Form")
        'Council
        .Range("I6").Interior.Color = xlNone
        .Range("I6").Value = ""
        
        'Content Presented
        .Range("I8").Interior.Color = xlNone
        .Range("I8").Value = ""
        
        'Decisions Made by Council
        .Range("I13").Interior.Color = xlNone
        .Range("I13").Value = ""
        
        'Icons
        .Range("I15").Interior.Color = xlNone
        .Range("I15").Value = ""
        
        'Decison Log
        .Range("E19").Interior.Color = xlNone
        .Range("E19").Value = ""
        
        .Range("E20").Interior.Color = xlNone
        .Range("E20").Value = ""
        
        .Range("E21").Interior.Color = xlNone
        .Range("E21").Value = ""
        
        .Range("E22").Interior.Color = xlNone
        .Range("E22").Value = ""
        
        .Range("I19").Interior.Color = xlNone
        .Range("I19").Value = ""
        
        .Range("I20").Interior.Color = xlNone
        .Range("I20").Value = ""
        
        .Range("I21").Interior.Color = xlNone
        .Range("I21").Value = ""
        
        .Range("I22").Interior.Color = xlNone
        .Range("I22").Value = ""
        
        'Follow Up
        .Range("I24").Interior.Color = xlNone
        .Range("I24").Value = ""
        
        'Action Needed by Council
        .Range("I29").Interior.Color = xlNone
        .Range("I29").Value = ""
        
        'Action Needed by ICC/ICB
        .Range("I34").Interior.Color = xlNone
        .Range("I34").Value = ""
        
        'Next Meeting Date
        .Range("I39").Interior.Color = xlNone
        .Range("I39").Value = ""
    End With
End Sub


Sub Save()

    Dim frm As Worksheet
    Dim database As Worksheet
    
    Dim iRow As Long
    Dim iSerial As Long
    
    Set frm = ThisWorkbook.Sheets("Form")
    Set database = ThisWorkbook.Sheets("Database")
    
    If Trim(frm.Range("M1").Value) = "" Then
        iRow = database.Range("A" & Application.Rows.count).End(xlUp).Row + 1
        
        If iRow = 2 Then
            
            iSerial = 1
        
        Else
        
            iSerial = database.Cells(iRow - 1, 1).Value + 1
        
        End If
    
    Else
        iRow = frm.Range("L1").Value
        iSerial = frm.Range("M1").Value
        
    End If
    
    
    With database
        
        .Cells(iRow, 1).Value = iSerial
        .Cells(iRow, 2).Value = frm.Range("I6").Value
        .Cells(iRow, 3).Value = frm.Range("I8").Value
        .Cells(iRow, 4).Value = frm.Range("E19").Value
        .Cells(iRow, 5).Value = frm.Range("I19").Value
        .Cells(iRow, 6).Value = frm.Range("I24").Value
        .Cells(iRow, 7).Value = frm.Range("I29").Value
        .Cells(iRow, 8).Value = frm.Range("I34").Value
        .Cells(iRow, 9).Value = frm.Range("I39").Value
        .Cells(iRow, 10).Value = Application.UserName
        .Cells(iRow, 11).Value = [Text(Now(), "DD-MM-YYYY HH:MM:SS")]
        
        If Trim(frm.Range("I20").Value) <> "" Then
            iRow = iRow + 1
            .Cells(iRow, 1).Value = iSerial
            .Cells(iRow, 2).Value = frm.Range("I6").Value
            .Cells(iRow, 3).Value = frm.Range("I8").Value
            .Cells(iRow, 4).Value = frm.Range("E20").Value
            .Cells(iRow, 5).Value = frm.Range("I20").Value
            .Cells(iRow, 6).Value = frm.Range("I24").Value
            .Cells(iRow, 7).Value = frm.Range("I29").Value
            .Cells(iRow, 8).Value = frm.Range("I34").Value
            .Cells(iRow, 9).Value = frm.Range("I39").Value
            .Cells(iRow, 10).Value = Application.UserName
            .Cells(iRow, 11).Value = [Text(Now(), "DD-MM-YYYY HH:MM:SS")]
        End If
        
        If Trim(frm.Range("I21").Value) <> "" Then
            iRow = iRow + 1
            .Cells(iRow, 1).Value = iSerial
            .Cells(iRow, 2).Value = frm.Range("I6").Value
            .Cells(iRow, 3).Value = frm.Range("I8").Value
            .Cells(iRow, 4).Value = frm.Range("E21").Value
            .Cells(iRow, 5).Value = frm.Range("I21").Value
            .Cells(iRow, 6).Value = frm.Range("I24").Value
            .Cells(iRow, 7).Value = frm.Range("I29").Value
            .Cells(iRow, 8).Value = frm.Range("I34").Value
            .Cells(iRow, 9).Value = frm.Range("I39").Value
            .Cells(iRow, 10).Value = Application.UserName
            .Cells(iRow, 11).Value = [Text(Now(), "DD-MM-YYYY HH:MM:SS")]
        End If
        
        If Trim(frm.Range("I22").Value) <> "" Then
            iRow = iRow + 1
            .Cells(iRow, 1).Value = iSerial
            .Cells(iRow, 2).Value = frm.Range("I6").Value
            .Cells(iRow, 3).Value = frm.Range("I8").Value
            .Cells(iRow, 4).Value = frm.Range("E22").Value
            .Cells(iRow, 5).Value = frm.Range("I22").Value
            .Cells(iRow, 6).Value = frm.Range("I24").Value
            .Cells(iRow, 7).Value = frm.Range("I29").Value
            .Cells(iRow, 8).Value = frm.Range("I34").Value
            .Cells(iRow, 9).Value = frm.Range("I39").Value
            .Cells(iRow, 10).Value = Application.UserName
            .Cells(iRow, 11).Value = [Text(Now(), "DD-MM-YYYY HH:MM:SS")]
        End If
    
    End With
    
    frm.Range("L1").Value = ""
    frm.Range("M1").Value = ""

End Sub

Sub SubmitDecision()

    Dim frm As Worksheet
    'Dim decisionCount As Integer
    
    Set frm = ThisWorkbook.Sheets("Form")
    
    If Trim(frm.Range("I13").Value) = "" Then
        MsgBox "Decisions Made by Council field is blank.", vbOKOnly + vbInformation, "Decisions Made by Council"
        frm.Range("I13").Select
        frm.Range("I13").Interior.Color = vbRed
        Exit Sub
    End If
    
    If Trim(frm.Range("I15").Value) <> "Easy Decision" And Trim(frm.Range("I15").Value) <> "Big Change Impact" _
    And Trim(frm.Range("I15").Value) <> "Loud Dissenters" And Trim(frm.Range("I15").Value) <> "Close Vote" _
    And Trim(frm.Range("I15").Value) <> "None" Then
        MsgBox "Please select valid Decision Tag from Drop-down.", vbOKOnly + vbInformation, "Decision Tag"
        frm.Range("I15").Select
        frm.Range("I15").Interior.Color = vbRed
        Exit Sub
    End If
    
    'Checking which decision cell is open
    If Trim(frm.Range("E19").Value) = "" Then
        frm.Range("E19").Value = frm.Range("I13").Value
        frm.Range("I19").Value = frm.Range("I15").Value
        
        Call numDecisions(1)
        
        'Clearing decisions made by council cell and decision tags cell
        frm.Range("I13").Interior.Color = xlNone
        frm.Range("I13").Value = ""
        
        frm.Range("I15").Interior.Color = xlNone
        frm.Range("I15").Value = ""
    
    ElseIf Trim(frm.Range("E20").Value) = "" Then
        frm.Range("E20").Value = frm.Range("I13").Value
        frm.Range("I20").Value = frm.Range("I15").Value
        
        Call numDecisions(2)
        
        'Clearing decisions made by council cell
        frm.Range("I13").Interior.Color = xlNone
        frm.Range("I13").Value = ""
        
        frm.Range("I15").Interior.Color = xlNone
        frm.Range("I15").Value = ""
    
    ElseIf Trim(frm.Range("E21").Value) = "" Then
        frm.Range("E21").Value = frm.Range("I13").Value
        frm.Range("I21").Value = frm.Range("I15").Value
        
        Call numDecisions(3)
        
        'Clearing decisions made by council cell
        frm.Range("I13").Interior.Color = xlNone
        frm.Range("I13").Value = ""
        
        frm.Range("I15").Interior.Color = xlNone
        frm.Range("I15").Value = ""
    
    ElseIf Trim(frm.Range("E22").Value) = "" Then
        frm.Range("E22").Value = frm.Range("I13").Value
        frm.Range("I22").Value = frm.Range("I15").Value
        
        Call numDecisions(4)
        
        'Clearing decisions made by council cell
        frm.Range("I13").Interior.Color = xlNone
        frm.Range("I13").Value = ""
        
        frm.Range("I15").Interior.Color = xlNone
        frm.Range("I15").Value = ""
    End If

End Sub
 
Upvote 0
Edit: I commented out all the code that unlocks specific cells to make sure the buttons still work, and they don't. When you click on a button (in design mode or not), it just allows you to change the size of the button but does not run the macro behind it. This is my first time working in Excel VBA and I am stumped!! Any help is greatly appreciated.
I figured out this issue, the buttons had changed to pictures.
 
Upvote 0
Welcome to Mr Excel,

In your code you refer to Call SubmitDecision but you haven't shown that code.

Please use the code tags in the toolbar as it makes it easier for others to read your code.

Added note what code is behind Call Save & Reset?
I added the code! Thank you for the code tag tip
 
Upvote 0

Forum statistics

Threads
1,223,937
Messages
6,175,513
Members
452,650
Latest member
Tinfish

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top