+ Reply to Thread
Results 1 to 4 of 4

Adding comments & deleting comments VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    06-09-2007
    Posts
    29

    Adding comments & deleting comments VBA

    Hi

    As you can see from the code below... when i press the button... it adds the details i want in certain cells. It also adds a comment in the active cell in row 8.
    My problem is that how to i make a comment not appear if there is no text in there. This code always adds text in the box regardless of text or no text.

    Can anyone help?

    Private Sub CommandButton9_Click()
    r = ActiveCell.Row
    Rows(r).Select
    Selection.Insert Shift:=xlDown

    txt1 = txtcomment.Text
    'Updates the Cells
    Cells(r, "A") = cboCompanyName.Text
    Cells(r, "B") = cboRegion.Value
    Cells(r, "C") = TxtNameContact.Value
    Cells(r, "D") = TxtFaxNumber.Value
    Cells(r, "E") = TxtPhNumber.Value
    Cells(r, "F") = TxtAddress1.Value
    Cells(r, "G") = TxtAddress2.Value
    Cells(r, "H") = TxtSuburb.Value
    Cells(r, "I") = TxtCity.Value
    Cells(r, "J") = TxtPostcode.Value
    Cells(r, "K") = Txtemailaddress.Value
    'Range(Cells(r, "A"), Cells(r, "A")).comment.Delete
    Range(Cells(r, "A"), Cells(r, "A")).AddComment
    Range(Cells(r, "A"), Cells(r, "A")).comment.Visible = False
    Range(Cells(r, "A"), Cells(r, "A")).comment.Text Text:="" & txt1 & ""
    MsgBox ("New Contact Added for " & cboCompanyName.Text & "")

    End Sub

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Bracket the code that adds the comment with
    If txt1 <> "" Then
    '...
    End If

  3. #3
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Try doing a test on the length of txt1. If the length is >0 then add the comment

    if len(txt1) > 0 then
    'Range(Cells(r, "A"), Cells(r, "A")).comment.Delete
    Range(Cells(r, "A"), Cells(r, "A")).AddComment
    Range(Cells(r, "A"), Cells(r, "A")).comment.Visible = False
    Range(Cells(r, "A"), Cells(r, "A")).comment.Text Text:="" & txt1 & ""
    MsgBox ("New Contact Added for " & cboCompanyName.Text & "")
    end if
    HTH

    rylo

  4. #4
    Registered User
    Join Date
    06-09-2007
    Posts
    29
    Thanks mate. It works perfectly now!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1