insert comments

kamranyd

Board Regular
Joined
Apr 24, 2018
Messages
142
Office Version
  1. 2021
Platform
  1. Windows
is there any vba code for inserting comments in a active cell and if a cell has already comments than show pop message that cell has already comments do you want to edit or no or delete comments.

is there any vba code who can do this.
 
Last edited:
thnks yongle and others also. really you guys r so much help.
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
or try this..

Code:
[I][COLOR=#ff0000]Place this code in the SHEET module and then double click on any cell to test[/COLOR][/I]
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim OldComment As String, NewComment As String
    Cancel = True
    If Target.Count > 1 Then Exit Sub
    
    If Not Target.Comment Is Nothing Then
        OldComment = Target.Comment.Text
        Target.Comment.Delete
    End If
    NewComment = InputBox("Amend or delete comment", "", OldComment)
    If Not NewComment = vbNullString Then Target.AddComment Text:=NewComment
End Sub

Can u add codes for resizing comment box according to text enter and fonts size using and colors
 
Upvote 0
Try this:
I added three lines of code to posting made by previous poster.

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    'Modified 6/24/18 2:41 AM EDT
    Dim OldComment As String, NewComment As String
    Cancel = True
    If Target.Count > 1 Then Exit Sub
    
    If Not Target.Comment Is Nothing Then
        OldComment = Target.Comment.Text
        Target.Comment.Delete
    End If
    NewComment = InputBox("Amend or delete comment", "", OldComment)
    If Not NewComment = vbNullString Then Target.AddComment Text:=NewComment
    
    Target.Comment.Shape.TextFrame.Characters.Font.Size = 16  'New Line of code
    Target.Comment.Shape.TextFrame.AutoSize = True  ' New Line of code
    Target.Comment.Shape.Fill.ForeColor.SchemeColor = 3  'New line of code
End Sub

'You can modify to your exact needs.
 
Last edited:
Upvote 0
I missed one part.

Try this instead of my previous post:
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    'Modified 6/24/18 7:11 AM EDT
    Dim OldComment As String, NewComment As String
    Cancel = True
    If Target.Count > 1 Then Exit Sub
    
    If Not Target.Comment Is Nothing Then
        OldComment = Target.Comment.Text
        Target.Comment.Delete
    End If
    NewComment = InputBox("Amend or delete comment", "", OldComment)
    If Not NewComment = vbNullString Then
    Target.AddComment Text:=NewComment
    
    Target.Comment.Shape.TextFrame.Characters.Font.Size = 16  'New Line of code
    Target.Comment.Shape.TextFrame.AutoSize = True  ' New Line of code
   Target.Comment.Shape.Fill.ForeColor.SchemeColor = 3  'New line of code
End If
End Sub
 
Upvote 0
thnx, but new lines giving compile error "end if without block if"
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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