Lock cells when text entered into another vba not working

P4444

New Member
Joined
Nov 5, 2023
Messages
1
Office Version
  1. 365
Platform
  1. Windows
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
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Forum statistics

Threads
1,215,076
Messages
6,122,984
Members
449,092
Latest member
Mr Hughes

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