Consulting

Results 1 to 6 of 6

Thread: comment time

  1. #1
    VBAX Mentor
    Joined
    Jun 2005
    Posts
    374
    Location

    comment time

    hello
    this macro
    [VBA]Sub CommentDateTimeAdd()
    'adds comment with date and time,
    ' positions cursor at end of comment text
    Dim strDate As String
    Dim cmt As Comment strDate = "dd-mmm-yy hh:mm:ss"
    Set cmt = ActiveCell.Comment
    If cmt Is Nothing Then
    Set cmt = ActiveCell.AddComment
    cmt.text text:=Format(Now, strDate) & Chr(10)
    Else cmt.text text:=cmt.text & Chr(10) _ & Format(Now, strDate) & Chr(10)
    End If
    With cmt.Shape.TextFrame
    .Characters.Font.Bold = False
    End With
    SendKeys "%ie~"
    End Sub
    [/VBA]
    puts date and time in a comment .while this macro
    [VBA]Sub commentalony()
    Dim cm As Comment
    Dim c As Range
    For Each c In selection.Cells
    c.clearcomments
    If Not IsEmpty(c) And c.HasFormula Then
    With c.AddComment
    .Text Text:="Formula:" & c.Formula
    .Shape.TextFrame.AutoSize = True
    End With
    End If
    Next c
    End Sub
    [/VBA] adds a formula of activecell to a comment.can this macro be merged to one that will present formula in active cell with the time and date comment was created?
    thanks
    Last edited by mdmackillop; 02-23-2006 at 03:50 PM. Reason: Breaks added
    moshe

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]
    Sub commentalony()
    Dim cm As Comment
    Dim c As Range
    Dim strDate As String
    strDate = "dd-mmm-yy hh:mm:ss"
    For Each c In Selection.Cells
    c.ClearComments
    If Not IsEmpty(c) And c.HasFormula Then
    With c.AddComment
    .Text Text:=Format(Now, strDate) & Chr(10) & _
    "Formula:" & c.Formula
    .Shape.TextFrame.AutoSize = True
    End With
    End If
    Next c
    End Sub
    [/vba]

  3. #3
    Is there any way to display the results of a formula in the comment box?

  4. #4
    VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    [VBA]Option Explicit
    Sub CommentThem()
    Dim cell As Range
    On Error Resume Next
    Selection.ClearComments
    On Error GoTo 0
    For Each cell In Intersect(Selection, ActiveSheet.UsedRange)
    If cell.Formula <> "" Then
    cell.AddComment
    cell.Comment.Visible = False
    On Error Resume Next 'fails on invalid formula
    cell.Comment.Text Text:=cell.Address(0, 0) & _
    " value: " & cell.Value & Chr(10) & _
    " format: " & cell.NumberFormat & Chr(10) & _
    " Formula: " & cell.Formula
    On Error GoTo 0
    End If
    Next cell
    End Sub[/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  5. #5
    Once again.. Thanks Steve!

  6. #6
    VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Glad to help Buckeye...
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

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