Consulting

Results 1 to 6 of 6

Thread: Solved: Delete only today comment?

  1. #1
    VBAX Regular deedii's Avatar
    Joined
    Dec 2011
    Posts
    50
    Location

    Solved: Delete only today comment?

    Hi guys Im having a trouble with the track comment I was using from kb repo. I was using this code below on my sheet to track cell changes as comment.

    [VBA]
    Option Explicit
    Public preValue As Variant
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    Target.ClearComments
    Target.AddComment.Text Text:="Previous Value was " & preValue & Chr(10) & "Revised " & Format(Date, "mm-dd-yyyy") & Chr(10) & "By " & Environ("UserName")
    End Sub

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    If Target = "" Then
    preValue = "a blank"
    Else: preValue = Target.Value
    End If
    End Sub
    [/VBA]

    And this one to delete the comment.

    [VBA]
    Sub clean()
    Dim wks As Worksheet
    Dim cmnt As Comment
    For Each wks In ActiveWorkbook.Sheets
    For Each cmnt In wks.Comments
    cmnt.Delete
    Next cmnt
    Next
    End Sub
    [/VBA]

    Now my problem is each time i run clean() all comments are being erased. I want only comment created today are the only one to delete not to include past comment that was created. How can I do that? Thank you

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    [vba]Sub clean()
    Dim wks As Worksheet
    Dim cmnt As Comment
    For Each wks In ActiveWorkbook.Sheets
    For Each cmnt In wks.Comments
    If InStr(cmnt.Text, Format(Date, "mm-dd-yyyy")) > 0 Then cmnt.Delete
    Next cmnt
    Next
    End Sub
    [/vba]but it won't restore previous comments.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Regular deedii's Avatar
    Joined
    Dec 2011
    Posts
    50
    Location
    Thanks for the quick response. No its ok as long as it doesnt delete comments created in the past days.
    Thanks you so much x0x0
    Last edited by deedii; 01-31-2012 at 04:51 PM.

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Quote Originally Posted by deedii
    Thanks for the quick response. So it should delete only comment that was created today?
    Yes.
    Quote Originally Posted by deedii
    Shoul i still edit this one "mm-dd-yyyy"?
    I don't think so. It should be the same date format as in the line:
    Target.AddComment.Text Text:="Previous Value was " & preValue & Chr(10) & "Revised " & Format(Date, "mm-dd-yyyy") & Chr(10) & "By " & Environ("UserName")
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #5
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Quote Originally Posted by deedii
    Thanks for the quick response. No its ok as long as it doesnt delete comments created in the past days.
    Thanks you so much x0x0
    Clean doesn't, but you do when you change a cell. and that can't be restored
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  6. #6
    VBAX Regular deedii's Avatar
    Joined
    Dec 2011
    Posts
    50
    Location
    I see thanks so much for the help. This is solved.

Posting Permissions

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