I have a cell that is named DATA_FIELD_NAME and I would like to use it in the following way:
Private Sub LockCells(iNumberOfDataColumns As Long)
ActiveSheet.Unprotect
ActiveSheet.Cells.Locked = False
ActiveSheet.Range("DATA_FIELD_NAME:DATA_FIELD_NAME+iNumberOfDataColumns").Locked = True
ActiveSheet.Protect Contents:=True
End Sub
Essentially I would like to lock the range of cells starting from the DATA_FIELD_NAME cell horizontally to DATA_FIELD_NAME + n.
However this doesn’t work. Could someone please tell me the correct syntax or an alternate method?
I’d try this:
ActiveSheet.Range("DATA_FIELD_NAME").Resize(1, iNumberOfDataColumns).Locked = TrueHere is a reference on Range.Resize Basically it changes the amount of cells you are dealing with based upon the current range. In what I gave you, it changes to 1 row, and iNumberOfDataColumns columns.