delete comment if present in VBA

VBA_Newbie123

New Member
Joined
May 20, 2017
Messages
9
Hi Team,

I have a macro that works fine that adds a comment to the cells but if there is one there already it will stop. What I was hoping to do was rather that delete the comment, could I append another comment to it rather than delete and lose the previous one? Code as below for the part i'm trying to fix;

Code:
If OptionButton2.Value = True Then     ActiveCell.Offset(0, 5) = "0"
    ActiveCell.Offset(0, 5).Activate
    ActiveCell.AddComment
    ActiveCell.comment.Text Text:=Environ("username") & Chr(10) & "Zeroed" & Chr(10) & Date & Chr(10) & Time()
    ActiveCell.comment.Visible = False
    
    ActiveCell.Offset(0, 1).Activate
    ActiveCell.AddComment
    ActiveCell.comment.Text Text:=Environ("username") & Chr(10) & "Zeroed" & Chr(10) & Date & Chr(10) & Time()
    ActiveCell.comment.Visible = False
    ActiveCell.Offset(0, 0) = "0"
    
    ActiveCell.Offset(0, 1).Activate
    ActiveCell.Offset(0, 0) = "0"
    ActiveCell.AddComment
    ActiveCell.comment.Text Text:=Environ("username") & Chr(10) & "Zeroed" & Chr(10) & Date & Chr(10) & Time()
    ActiveCell.comment.Visible = False
    
    End If
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Here is a simple script as a example to what you want.
Modify your script as needed

Code:
Sub Add_My_Comment()
'Modified  1/24/2019  10:46:18 PM  EST
Dim cmt As Comment
Set cmt = ActiveCell.Comment
    If cmt Is Nothing Then
        ActiveCell.AddComment Text:="Me"
    Else
ActiveCell.Comment.Text Text:=ActiveCell.Comment.Text & vbNewLine & "You"
    
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,902
Messages
6,175,278
Members
452,629
Latest member
SahilPolekar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top