VBA for Cell Comment with User Name, Text Description, Cell Value & Date

rtehlan

New Member
Joined
Mar 23, 2017
Messages
19
Hi,

Any help on this would be greatly appreciated, i have already spent so much time on this & nothing is of any help. I need a VBA which i can run on a selected cell & get the cell comment with user name, Text Description with Cell Value & Current date just like below:

Tehlan, Romil:

Value at Detailed Review : (106,506)
Date: 3/23/2017


Thank you
Romil
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Try something like this...

Code:
[color=darkblue]Option[/color] [color=darkblue]Explicit[/color]

[color=darkblue]Sub[/color] AddComment()
    
    [color=darkblue]Dim[/color] sText [color=darkblue]As[/color] [color=darkblue]String[/color]
    
    sText = Application.UserName & ":" & vbCrLf & vbCrLf
    sText = sText & "Value at Detailed Review:  (" & Format(Range("A2").Value, "#,##0") & ")" & vbCrLf
    sText = sText & "Date:  " & Format(Date, "m/dd/yyyy")
    
    [color=darkblue]With[/color] ActiveCell
        .ClearComments
        [color=darkblue]With[/color] .AddComment
            .Text sText
            [color=darkblue]With[/color] .Shape
                .TextFrame.Characters(1, InStr(sText, ":")).Font.Bold = msoTrue
                .Width = 180
                .Height = 60
            [color=darkblue]End[/color] [color=darkblue]With[/color]
        [color=darkblue]End[/color] [color=darkblue]With[/color]
    [color=darkblue]End[/color] [color=darkblue]With[/color]
    
[color=darkblue]End[/color] [color=darkblue]Sub[/color]

Hope this helps!
 
Upvote 0
Thank you so much, Almost Working perfectly but only it is picking the cell value from "Cell A2" instead of that particular cell i select & run the code.
 
Upvote 0
Thank you so much,

You're very welcome!

Almost Working perfectly but only it is picking the cell value from "Cell A2" instead of that particular cell i select & run the code.

If the selected cell is empty/blank, how do you want the code to proceed?
 
Upvote 0
i will be not be using this on any blank cell or a range. rather than on 1 cell at a time with a value. even if i just use this on a blank cell i would want 0 as the value on Detailed Review.
 
Upvote 0
Try...

Code:
Sub AddComment()
    
    [COLOR=#ff0000]Dim vCellValue As Variant[/COLOR]
    Dim sText As String
    
    [COLOR=#ff0000]vCellValue = ActiveCell.Value
    If IsNumeric(vCellValue) Then
        vCellValue = CDbl(vCellValue)
    End If[/COLOR]
    
    sText = Application.UserName & ":" & vbCrLf & vbCrLf
    sText = sText & "Value at Detailed Review:  (" & Format([COLOR=#ff0000]vCellValue[/COLOR], "#,##0") & ")" & vbCrLf
    sText = sText & "Date:  " & Format(Date, "m/dd/yyyy")
    
    With ActiveCell
        .ClearComments
        With .AddComment
            .Text sText
            With .Shape
                .TextFrame.Characters(1, InStr(sText, ":")).Font.Bold = msoTrue
                .Width = 180
                .Height = 60
            End With
        End With
    End With
    
End Sub

Hope this helps!
 
Upvote 0
Adding to this, If there is any way each time i use this macro it does not supersede the existing one & adds the comments above or below the existing text on comment box ? So that there is a history

For Eg.
Tehlan, Romil:

Value at Detailed Review : (106,506)
Date: 3/23/2017

Tehlan, Romil:

Value at Detailed Review : (100,000)
Date: 8/20/2018

& So on. Also is there anyway to change the color of the comment box instead of default pale yellow color in the code ? Wanted to distinguish these comments from other
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,429
Messages
6,119,433
Members
448,897
Latest member
ksjohnson1970

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