Hi All,

I searched on the forum and found a previous post that matched my situation.

I'm trying to created a MsgBox with a message when a user tries to edit a protected cell in a workbook (I don't want the default message that Excel produces when you edit a protected cell).

I've used the following code from a previous post, but can't seem to get it to work:

Option Explicit


Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    Dim vUnlockedCell As Variant
    Dim rUnlockedCells As Range

'   Specify the address of the first user-editable cell here
    Set rUnlockedCells = Me.Range("AO5")

'   Specify the addresses of the remaining user-editable cell here
    For Each vUnlockedCell In Array("AO7:AR260")
        Set rUnlockedCells = Union(rUnlockedCells, Me.Range(vUnlockedCell))
    Next vUnlockedCell

    If Union(Target, rUnlockedCells).Address <> rUnlockedCells.Address Then
        MsgBox "This selection may not be edited", vbExclamation, "Invalid selection"
    End If

End Sub
Anyone any suggestions?