Using VBA to lock a range of cells based on the value of another cell.

Syracuse

New Member
Joined
May 3, 2023
Messages
2
Office Version
  1. 365
Hi- I am looking for a VBA code that will lock a range of cells (D6:F6) when the value in cell B6="Submit". I want this to continue down to row 250 (so if cell B16="Submit" then cells D16:F:16 will then lock). My sheet has a password, right now it is "Test". I also need the cells in column B to lock once a cell is marked "Submit". I have the code below that locks the B column cells but I have no idea how to combine that with other VBA code.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Set rng = Range("B6:B250")
ActiveSheet.Unprotect Password:="Test"
For Each cell In rng
If cell.Value <> "" Then
cell.Locked = True
End If
Next
ActiveSheet.Protect Password:="Test"
End Sub

Any help would be so appeciated for this newbie!
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
hey @mumps, I've seen some of your answers on other threads and I tried to use what you wrote but was unsuccessful.
Any chance you could help me out?
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,160
Members
453,021
Latest member
Justyna P

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