Dear All
Please find the attached excel file. I was creating a GL Code Generator and I want to lock the cell range B5:I5 as soon as I select "Authorised" in column I5 and the same should repeat in the next row as well. I found a VBA code that helped me a lot but, I have to write the same code over and over to achieve the results. below I have pasted the VBA code that I am using. Please help.... thnx
Please find the attached excel file. I was creating a GL Code Generator and I want to lock the cell range B5:I5 as soon as I select "Authorised" in column I5 and the same should repeat in the next row as well. I found a VBA code that helped me a lot but, I have to write the same code over and over to achieve the results. below I have pasted the VBA code that I am using. Please help.... thnx
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Unprotect
If ActiveSheet.Cells(5, 9).Text = "Authorised" Then
ActiveSheet.Range(Cells(5, 2), Cells(5, 9)).Locked = True
Else
ActiveSheet.Range(Cells(5, 2), Cells(5, 9)).Locked = False
End If
If ActiveSheet.Cells(6, 9).Text = "Authorised" Then
ActiveSheet.Range(Cells(6, 2), Cells(6, 9)).Locked = True
Else
ActiveSheet.Range(Cells(6, 2), Cells(6, 9)).Locked = False
End If
If ActiveSheet.Cells(7, 9).Text = "Authorised" Then
ActiveSheet.Range(Cells(7, 2), Cells(7, 9)).Locked = True
Else
ActiveSheet.Range(Cells(7, 2), Cells(7, 9)).Locked = False
End If
If ActiveSheet.Cells(8, 9).Text = "Authorised" Then
ActiveSheet.Range(Cells(8, 2), Cells(8, 9)).Locked = True
Else
ActiveSheet.Range(Cells(8, 2), Cells(8, 9)).Locked = False
End If
If ActiveSheet.Cells(9, 9).Text = "Authorised" Then
ActiveSheet.Range(Cells(9, 2), Cells(9, 9)).Locked = True
Else
ActiveSheet.Range(Cells(9, 2), Cells(9, 9)).Locked = False
End If
If ActiveSheet.Cells(10, 9).Text = "Authorised" Then
ActiveSheet.Range(Cells(10, 2), Cells(10, 9)).Locked = True
Else
ActiveSheet.Range(Cells(10, 2), Cells(10, 9)).Locked = False
End If
ActiveSheet.Protect
End Sub