ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Lock Row (A~F) based on criteria in g (https://www.excelbanter.com/excel-programming/446567-lock-row-%7Ef-based-criteria-g.html)

nhkhurum

Lock Row (A~F) based on criteria in g
 
I have lot of data in sheet 1 (for whole years) I want to lock cell from A~F when in cell G i give some criteria Like Posted. Whole the sheet remain unprotected.

Regards

Noor

Auric__

Lock Row (A~F) based on criteria in g
 
nhkhurum wrote:

I have lot of data in sheet 1 (for whole years) I want to lock cell from
A~F when in cell G i give some criteria Like Posted. Whole the sheet
remain unprotected.


To lock all of the cells in A:F in the current row based on the contents of G
[current row], it's like this:

Sub lockWhenCriteriaMet1()
Dim cell As Range
For Each cell In Range("G:G")
If cell.Value = criteria Then
Range("A" & cell.Row & ":F" & cell.Row).Locked = True
End If
Next
End Sub

If the cells are locked individually, based on G, then it's more like this:

Sub lockWhenCriteriaMet2()
Dim cell As Range
For Each cell In Range("G:G")
Select Case cell.Value
Case criteria_A
Cells(cell.Row, 1).Locked = True
Case criteria_B
Cells(cell.Row, 2).Locked = True
'etc...
End Select
Next
End Sub

--
Sacrificing minions: is there any problem it CAN'T solve?


All times are GMT +1. The time now is 09:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com