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".
Changed it but still having same error,
How exactly did you change it? By changing the name, or moving the code?
What Sheet number did you move it to?
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

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