excel vba - How to disable the rowsin Sheet1 based on values on other sheet2 -
i trying disable rows in sheet1 ,the range based on values based on sheet2. sheet comprise of rows titles , sheet2 have title having value in either 0 or 1. depending upon whether title value in sheet2 0 or 1, disabled or enabled in sheet1.
0 value in sheet 2 - row should disabled in sheet1.
1 value in sheet2 - row should enabled in sheet1.
hello please see below code, code in sheet2 range a1 a50 "0" , "1" lock same rows in sheet1 accordingly:
sub lockingrows() dim wb workbook dim ws1 worksheet dim ws2 worksheet dim c range set wb = activeworkbook set ws1 = wb.sheets("sheet1") set ws2 = wb.sheets("sheet2") ws1.unprotect password:="pass" '<--- password ws1.cells.locked = false each c in ws2.range("a1:a50").cells '<--- range in sheet2 0 , 1 if c.value = 1 ws1.rows(c.row & ":" & c.row).locked = true elseif c.value = 0 ws1.rows(c.row & ":" & c.row).locked = false end if next ws1.protect password:="pass", userinterfaceonly:=true '<--- password end sub
Comments
Post a Comment