vendredi 30 novembre 2018

VBA - EASY: Lock Range (in the same row) when A"counter" is FALSE

Please help me with this easy question:

IF A2 is TRUE I want to lock the Range D2:I2

IF A3 is TRUE I want to lock the Range D3:I3...

IF AxRow is TRUE I want to lock the Range DxRow:IxRow

I have 744 rows (A2:A745) with TRUE or FALSE statements. And when the FALSE statement appears, all the following cells are FALSE. Example: A2 =TRUE ...A22 = TRUE, A23 = TRUE, A24 = TRUE, A25 = FALSE, A26 = FALSE... A745 = FALSE.

Please, what is the problem with my code?

Private Sub Block(ByVal Target As Excel.Range)

Dim xRow As Long
xRow = 2
ThisWorkbook.ActiveSheet.Unprotect Password:="123"
Do Until Cells(xRow, 1).Value = False
If Worksheets("HourlyCount").Cells(xRow, 1).Value = True Then
Range("D" & xRow & ":I" & xRow).Locked = True
End If
xRow = xRow + 1
Loop
ThisWorkbook.ActiveSheet.Protect Password:="123"


End Sub

Aucun commentaire:

Enregistrer un commentaire