Search for variable in Column and Lock cell

Sam11586

New Member
Joined
Jul 15, 2021
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hi Everyone,

In my VBA code, I am looking to form a loop which can check the variables in Column A and for couple of variables in Column A unlock cell/cells from column D and For rest of the variables lock cell/cells from Column D & M.

Currently I have with error:

Private Sub Worksheet_Change()

Dim iRow As Long
Dim iLastRow As Long

iRow = 1
iLastRow = Bu1Calcsheet.cells(Rows.count, 1).End(xlUp).Row
Do While iRow<=iLastRow

If bu1CalcSheet.Cells(iRow, 1) Like "ABC" or bu1CalcSheet.Cells(iRow, 1) Like "XYZ" Then
bu1CalcSheet.Range("D" & iRow).Locked =False
bu1CalcSheet.Range("M" & iRow).Locked =False

ElseIf bu1CalcSheet.Cells(iRow, 1) Like "JKL" or bu1CalcSheet.Cells(iRow, 1) Like "DYU" or bu1CalcSheet.Cells(iRow, 1) Like "SPP" Then
bu1CalcSheet.Range("D" & iRow).Locked = True

End If
iRow=iRow+1
Loop
End Sub

Any idea?
 
I have
Worksheet_Change needs to go in one of the pre-defined Sheet modules in order to work automatically (specifically, the sheet you want it to run against), not one a General/Standard module.

The module should look something like:
SheetX (Sheet Name)
where
X is some number
Sheet Name is the name of the sheet.
Changed it but still having same error,
Any idea or other code which solve my query?
 
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,224,827
Messages
6,181,194
Members
453,021
Latest member
pingpong7117

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