Set range for macro running [Closed]

Report
Posts
5
Registration date
Thursday October 27, 2016
Status
Member
Last seen
November 5, 2016
-
Posts
2675
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
November 5, 2020
-
if i have macro locked cells with change value of other cell , but this macro work from A1


i ask if i can modified code to let macro begin from row 9

this is my macro

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

ActiveSheet.Unprotect Password:=""

If Range("a" & Target.Row & ":a" & Target.Row).Value = 1 Then

Range("b" & Target.Row & ":b" & Target.Row).EntireColumn.Locked = True

Else
Range("b" & Target.Row & ":b" & Target.Row).EntireColumn.Locked = False


End If



ActiveSheet.Protect Password:="", DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub

1 reply

Posts
2675
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
November 5, 2020
448
Hi a_elgazar,

Start your code with:
If Target.Row < 9 then exit sub

Best regards,
Trowa
Posts
5
Registration date
Thursday October 27, 2016
Status
Member
Last seen
November 5, 2016

thanks sir

but still i have problem want ask you about it ;

if i have ( b2-d2) merged

when i try the previous code tell me

unable to set the locked property in the range class

do you have an idea to solve this problem
Posts
2675
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
November 5, 2020
448
Hi a_elgazar,

For that you will have to unmerge first, then lock/unlock cells and then merge again.

If you can't write that part of the code, then let me know which cells are merged (i.e.B2-D2 for 100 rows).

Best regards,
Trowa

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!