Consulting

Results 1 to 8 of 8

Thread: Solved: Adding and Deleting Comments

  1. #1

    Solved: Adding and Deleting Comments

    Okay, I have the following code:

    [VBA]
    Sub ValidateConsolidationSheet()
    Dim x As Integer
    Dim wSheets As Worksheet

    Set wSheets = Worksheets("Sheet1")

    For x = 1 To 5
    If Range("EndingBalance" & x) <> Range("PerGL" & x) Then
    wSheets.Unprotect SYSID
    wSheets.Range("EndingBalance" & x).Interior.ColorIndex = 6
    wSheets.Range("EndingBalance" & x).AddComment ("Ending Balance must equal PerGL82")
    wSheets.Protect SYSID
    Else
    wSheets.Unprotect SYSID
    wSheets.Range("EndingBalance" & x).Interior.ColorIndex = 0
    wSheets.Protect SYSID
    End If
    Next x
    End Sub

    [/VBA]

    However, with the AddComment line, I get a VBA error: 400 (whatever THAT means).

    What am I doing incorrectly?

  2. #2
    Administrator
    2nd VP-Knowledge Base
    VBAX Master malik641's Avatar
    Joined
    Jul 2005
    Location
    Florida baby!
    Posts
    1,533
    Location
    I thought that what you have should work....but give this a try:

    [vba]Sub ValidateConsolidationSheet()
    Dim x As Integer
    Dim wSheets As Worksheet

    Set wSheets = Worksheets("Sheet1")

    For x = 1 To 5
    If Range("EndingBalance" & x) <> Range("PerGL" & x) Then
    wSheets.Unprotect SYSID
    wSheets.Range("EndingBalance" & x).Interior.ColorIndex = 6

    With wSheets.Range("EndingBalance" & x)
    .AddComment
    .Comment.Text Text:="Ending Balance must equal PerGL82"
    End With

    wSheets.Protect SYSID
    Else
    wSheets.Unprotect SYSID
    wSheets.Range("EndingBalance" & x).Interior.ColorIndex = 0
    wSheets.Protect SYSID
    End If
    Next x
    End Sub[/vba]




    New to the forum? Check out our Introductions section to get to know some of the members here. Feel free to tell us a little about yourself as well.

  3. #3
    It still gives me the "400" error

  4. #4
    VBAX Expert
    Joined
    Jul 2004
    Location
    Wilmington, DE
    Posts
    600
    Location
    Tony,

    I see nothing obviously wrong with your code. It should work. The only thing I could think of is that maybe that cell already had a comment, but in that case the error should be 1004 (application-defined or object-defined error).

  5. #5
    Doi!

    You are correct ..... I'm an idiot ...

    Sorry about what turned out to be a stupid question ...

    However, now when I add a ClearComment line, I get the stupid error again.

  6. #6
    AHA!

    Got it!

    I got it with ClearComments because it was still trying to put a comment in elsewhere where there already was one.

    Thanks guys!

  7. #7
    VBAX Expert
    Joined
    Jul 2004
    Location
    Wilmington, DE
    Posts
    600
    Location
    Glad to help

  8. #8
    VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    If your question has been answered successfully, please mark the thread solved!!
    Last edited by austenr; 12-20-2005 at 02:03 PM. Reason: Added smiley
    Peace of mind is found in some of the strangest places.

Posting Permissions

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