Results 1 to 7 of 7

Thread: Worksheet_SelectionChange if Comment/Textbox

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,776
    This code will allow you to select a cell in 1:6 only if it has a comment. (how to insert a new comment, I don't know). Selecting a text box from the Drawing Menu doesn't trigger the SelectionChange event so that is N/A. I don't know if ActiveX text boxes act the same way.

    The logic could be smoother, but addressing the .Comment property of an uncommented cell throws an error.
    Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    If Not (Application.Intersect(Target, Range("1:6")) Is Nothing) Then
        Application.EnableEvents = False
        If Comments.Count = 0 Then
            Range("b7").Select
        Else
            If Application.Intersect(Target, Cells.SpecialCells(xlCellTypeComments)) Is Nothing Then
                Range("b7").Select
            End If
        End If
        Application.EnableEvents = True
    End If
    End Sub
    Apparently, SpecialCells triggers a SelectionChange event. This is puzzeling and rather than hijack this thread I'm going to start a new one.

    new thread: http://www.vbaexpress.com/forum/show...462#post132462
    Last edited by mikerickson; 02-18-2008 at 12:38 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •