Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enter Time and Date into Excel Comment Box 1

Status
Not open for further replies.

TriRyche

Technical User
Apr 1, 2004
42
US
I know barely enough c++ to be dangerous, was proficient with BASIC in the 80's, and can (somewhat) grasp the syntax in the VBA editor. I am currently teaching myself VBA, but do not want to reinvent the wheel.
It would be greatly appreciated if someone will point me in the right direction.
(or at least let me know if I'm in over my head!!).
Thanks
I am using the follow code to date-time stamp entries in the adjecent cell: (Thanks Zathras and jcrater!)
Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    With Target
       If .Count > 1 Then Exit Sub
       If Not Intersect(Range("A1:AA2000"), .Cells) Is Nothing Then
          Application.EnableEvents = False
          With .Offset(0, 1)
             .NumberFormat = "MM/dd/yy hh:mm:ss"
             .Value = Now
           End With
           Application.EnableEvents = True
       End If
    End With
End Sub
I would like to put the date and time stamp into the comment box of the cell the data is entered in.
Thanks for any help, it is greatly appreciated!

 
Hi,
Code:
    With Target
        .AddComment
        With .Comment
            .Visible = False
            .Text Text:=Format(Now, "MM/dd/yy hh:mm:ss")
        End With
    End With


Skip,
[sub]
[glasses] [red]Be advised:[/red] When you ignite a firecracker in a bowl of vanilla, chocolate & strawberry ice cream, you get...
Neopolitan Blownapart! [tongue][/sub]

 
Thanks Skip!

Could you help me boobie proof it?
It works until re-entering data.
I'll settle for doing nothing upon re-entering data or appending to the comment.

Thanks!
 
Code:
    With target
        If .Comment Is Nothing Then
            .AddComment
            With .Comment
                .Visible = False
                .Text Text:=Format(Now, "MM/dd/yy hh:mm:ss")
            End With
        End If
    End With

Skip,
[sub]
[glasses] [red]Be advised:[/red] When you ignite a firecracker in a bowl of vanilla, chocolate & strawberry ice cream, you get...
Neopolitan Blownapart! [tongue][/sub]

 
I still get run time error 1004 if I try to re-enter data into a cell.
 
please post your code for this procedure.

Skip,
[sub]
[glasses] [red]Be advised:[/red] When you ignite a firecracker in a bowl of vanilla, chocolate & strawberry ice cream, you get...
Neopolitan Blownapart! [tongue][/sub]

 
Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    With Target
       If .Count > 1 Then Exit Sub
       If Not Intersect(Range("A1:IV65536"), .Cells) Is Nothing Then
          Application.EnableEvents = False
          .AddComment
        With .Comment
            .Visible = False
            .Text Text:=Format(Now, "MM/dd/yy hh:mm:ss")
        End With
            With Target
        If .Comment Is Nothing Then
            .AddComment
            With .Comment
                .Visible = False
                .Text Text:=Format(Now, "MM/dd/yy hh:mm:ss")
            End With
        End If
    End With
           Application.EnableEvents = True
       End If
    End With
End Sub
 

Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
    With Target
       If .Count > 1 Then Exit Sub
       If Not Intersect(Range("A1:IV65536"), .Cells) Is Nothing Then
            Application.EnableEvents = False
            If .Comment Is Nothing Then
                .AddComment
                With .Comment
                    .Visible = False
                    .Text Text:=Format(Now, "MM/dd/yy hh:mm:ss")
                End With
            End If
            Application.EnableEvents = True
        End If
    End With
End Sub


Skip,
[sub]
[glasses] [red]Be advised:[/red] When you ignite a firecracker in a bowl of vanilla, chocolate & strawberry ice cream, you get...
Neopolitan Blownapart! [tongue][/sub]

 

Thanks a million!

I swear I entered it like that before, but I got blank comments, and thefore befuddled the code as such.

The self teaching proicess is going slow due to other obligations. I am looking forward to looking back at my starter projects and laughing. But for now this really helps.

BTW, when I would run into an error, I couldn't get the code to run again short of exiting Excel and restarting.
Is there a way to refresh or reactivate the VBA code?

Thanks again for all your help!


 
Hi,

If the code errors while EnableEvents is False, then no event will fire.

Rather than exit just run a line of code to assign EnableEvents True during your testing.

Also, this is where Error processing is essential. Use OnError Resume next and then test at various places in your code in order to recover gracefully.

Skip,
[sub]
[glasses] [red]Be advised:[/red] When you ignite a firecracker in a bowl of vanilla, chocolate & strawberry ice cream, you get...
Neopolitan Blownapart! [tongue][/sub]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top