G'day,
I have a macro that runs on my sheet perfectly fine, however, I have decided I would like to prevent it being run on any cell on the sheet. Users are making errors and running the macro on cells that they shouldn't.
Is there a modification I can make to the code to limit he execution to G5:T9
And if a user does run it on any other cell they are prompted with a custom error message?
Cheers,
Hayden
I have a macro that runs on my sheet perfectly fine, however, I have decided I would like to prevent it being run on any cell on the sheet. Users are making errors and running the macro on cells that they shouldn't.
Is there a modification I can make to the code to limit he execution to G5:T9
And if a user does run it on any other cell they are prompted with a custom error message?
VBA Code:
Sub MarkShiftCovered()
Dim sCmt As String
Dim rCell As Range
sCmt = InputBox( _
Prompt:="Have you covered this shift in it's entirety?" & vbCrLf & _
"Please add details of how the shift has been covered. ie. OFF roster, extensions.", _
Title:="Comment to Add")
If sCmt = "" Then
MsgBox "Not actioned. Has the shift been covered?"
If StrPtr(sCmt) = 0 Then Exit Sub 'user cancelled inputbox
Else
For Each rCell In Selection
With rCell
ActiveSheet.Unprotect
.ClearComments
.AddComment
.Comment.Text Text:=sCmt
End With
Next
End If
Set rCell = Nothing
Selection.Font.Color = RGB(0, 0, 0)
Selection.Interior.ColorIndex = xlNone
Selection.Font.Underline = False
Selection.Font.Bold = False
Selection.Font.Strikethrough = True
ActiveSheet.Protect DrawingObjects:=False
End Sub
Cheers,
Hayden