Hi
I'm currently setting up a template for work that will speed up data analysis. I've never used vba but I understand the principles and what I'm trying to achieve seems simple but it's not working.
I want to lock cells B13 to E15 when text is entered into D6. I'm using the following code but it doesn't do anything.
Private Sub CommandButton1_Click()
If Range("D6") > 0 Then
Range("B13:E15").Locked = True
ElseIf Range("D6") <= 0 Then
Range("B13:E15").Locked = False
End If
End Sub
The issue may be how the sheet is set up. When the workbook opens 9in read-only mode) all cells on the sheet are locked, with the exception of B6, C6, D6, E6 (samples 1, 2, 3 and 4 respectively) and B10:E15 (to enter data) and the sheet is protected. Currently when there are only 2 samples (B6 and C6) all cells remain unlocked for data entry but when there are 3 (D6) or 4 (+E6) samples then B13:E15 are greyed out using conditional formatting.
Ideally I'd like any data that may have been entered into B13:E15 to be removed and the cells locked. I was hoping that the code above would help with the locking but it doesn't seem to.
Thanks in advance
Paul
I'm currently setting up a template for work that will speed up data analysis. I've never used vba but I understand the principles and what I'm trying to achieve seems simple but it's not working.
I want to lock cells B13 to E15 when text is entered into D6. I'm using the following code but it doesn't do anything.
Private Sub CommandButton1_Click()
If Range("D6") > 0 Then
Range("B13:E15").Locked = True
ElseIf Range("D6") <= 0 Then
Range("B13:E15").Locked = False
End If
End Sub
The issue may be how the sheet is set up. When the workbook opens 9in read-only mode) all cells on the sheet are locked, with the exception of B6, C6, D6, E6 (samples 1, 2, 3 and 4 respectively) and B10:E15 (to enter data) and the sheet is protected. Currently when there are only 2 samples (B6 and C6) all cells remain unlocked for data entry but when there are 3 (D6) or 4 (+E6) samples then B13:E15 are greyed out using conditional formatting.
Ideally I'd like any data that may have been entered into B13:E15 to be removed and the cells locked. I was hoping that the code above would help with the locking but it doesn't seem to.
Thanks in advance
Paul