CarrieAWalton
New Member
- Joined
- Sep 4, 2017
- Messages
- 12
Hi all,
I'm updating a time in motion sheet at work. I have a worksheet full of command buttons which all input information into worksheets named "1st" through to "31st". These worksheets need to be password protected so that users can SEE the info contained within them, but not be able to EDIT the sheets (otherwise people fiddle their figures), so I'm adding code to unprotect the sheet, input the data, then protect it again.
However, my current code is messy (I don't fully understand VBA and tend to just bumble my way through) and I was hoping you lovely folks might be able to help me tidy it up. Here's a section of the code from one of my command buttons. I have eighteen to add the password unprotect/protect code to.
I hope you can help
I'm updating a time in motion sheet at work. I have a worksheet full of command buttons which all input information into worksheets named "1st" through to "31st". These worksheets need to be password protected so that users can SEE the info contained within them, but not be able to EDIT the sheets (otherwise people fiddle their figures), so I'm adding code to unprotect the sheet, input the data, then protect it again.
However, my current code is messy (I don't fully understand VBA and tend to just bumble my way through) and I was hoping you lovely folks might be able to help me tidy it up. Here's a section of the code from one of my command buttons. I have eighteen to add the password unprotect/protect code to.
I hope you can help
Code:
Private Sub CommandButton6_Click()
'Call-Inbound
If Range("A2") = "1" Then
ans = InputBox("Case reference:", "Input")
Sheets("1st").Unprotect Password:="TIM"
Sheets("1st").Range("A" & Sheets("1st").Range("A" & Rows.Count).End(xlUp).Row + 1).Value = ans
Sheets("1st").Protect Password:="TIM"
End If
If Range("A2") = "2" Then
ans = InputBox("Case reference:", "Input")
Sheets("2nd").Unprotect Password:="TIM"
Sheets("2nd").Range("A" & Sheets("2nd").Range("A" & Rows.Count).End(xlUp).Row + 1).Value = ans
Sheets("2nd").Protect Password:="TIM"
End If
If Range("A2") = "3" Then
ans = InputBox("Case reference:", "Input")
Sheets("3rd").Unprotect Password:="TIM"
Sheets("3rd").Range("A" & Sheets("3rd").Range("A" & Rows.Count).End(xlUp).Row + 1).Value = ans
Sheets("3rd").Protect Password:="TIM"
End If
If Range("A2") = "4" Then
ans = InputBox("Case reference:", "Input")
Sheets("4th").Unprotect Password:="TIM"
Sheets("4th").Range("A" & Sheets("4th").Range("A" & Rows.Count).End(xlUp).Row + 1).Value = ans
End If
End Sub