G
Guest
Hi all,
I wrote a macro that would change the colour and value of selected cell(s).
I want users to be able to use this macro only if the selected cell(s) are
not locked. (locked cells in the spreadsheet are the ones containing
formulas, and i don't want the users to change that). Here is the code i
wrote:
Sub Approved()
' check that selection is not a protected cell
With Selection
If .Locked = True Then
MsgBox "Sorry! You selected a locked cell."
Exit Sub
End If
End With
ActiveSheet.Unprotect
Selection.Interior.ColorIndex = 35 'Light Green
Selection.value = "Approved"
End Sub
The above code works well when the selection consists of one cell only, or
when the selection consists of a range of cells that all have the same
formatting (either ALL locked, or ALL unlocked). However, when i tested the
code by selecting a range that includes both locked and unlocked cells, the
code didn't seem to know the difference and was run according to the
formatting of the FIRST cell in the selected range.
What do i need to change in order to detect if there is at least one locked
cell in the selected range?
i'm using Excel 2003.
Many thanks
Tendresse
I wrote a macro that would change the colour and value of selected cell(s).
I want users to be able to use this macro only if the selected cell(s) are
not locked. (locked cells in the spreadsheet are the ones containing
formulas, and i don't want the users to change that). Here is the code i
wrote:
Sub Approved()
' check that selection is not a protected cell
With Selection
If .Locked = True Then
MsgBox "Sorry! You selected a locked cell."
Exit Sub
End If
End With
ActiveSheet.Unprotect
Selection.Interior.ColorIndex = 35 'Light Green
Selection.value = "Approved"
End Sub
The above code works well when the selection consists of one cell only, or
when the selection consists of a range of cells that all have the same
formatting (either ALL locked, or ALL unlocked). However, when i tested the
code by selecting a range that includes both locked and unlocked cells, the
code didn't seem to know the difference and was run according to the
formatting of the FIRST cell in the selected range.
What do i need to change in order to detect if there is at least one locked
cell in the selected range?
i'm using Excel 2003.
Many thanks
Tendresse