I have a command button on my Excel sheet which opens an application.inputbox, preloaded with the currently selected range, and appends the contents of the cells in that range to a comment on those cells.
I am using an if/else statement to check if the cancel button is clicked, but it is not exiting the sub; the code runs whether I click OK or Cancel. I think either the cancel button is not returning 'false' or my if statement is broken.
Here is the code:
Private Sub CommentLogButton_Click()
'This Sub Appends Cell Contents to Cell Comment
Dim rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "Range to Log"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
If WorkRng = False Then
Exit Sub
Else
For Each rng In WorkRng
rng.NoteText Text:=rng.NoteText & rng.Value & ", "
rng.Value = ""
Next
End If
End Sub