Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default Time Stamp help

Hi,

Currently I we have this VBA code that puts in the date and time
of last edit of the worksheet:


Private Sub Worksheet_Change(ByVal Target As Range)

Dim dateTemp As Date

ActiveSheet.Names.Add Name:="_timestamp", RefersTo:=Now()
dateTemp = Val(Mid(ActiveSheet.Names("_timestamp"), 2))

ActiveSheet.Name = Format(dateTemp, "MMM dd.hh.mm.ss")

End Sub


I am wonder if anyone can revise this so that when current Date
is returned the code dies; any changes made subsequently to the
worksheet the following day wouldn't change its value??



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 661
Default Time Stamp help

Gerard

Make your first line something like this

if ActiveSheet.Name = Format(dateTemp, "MMM dd.hh.mm.ss") then exit sub


"Gerard Sanchez" wrote:

Hi,

Currently I we have this VBA code that puts in the date and time
of last edit of the worksheet:


Private Sub Worksheet_Change(ByVal Target As Range)

Dim dateTemp As Date

ActiveSheet.Names.Add Name:="_timestamp", RefersTo:=Now()
dateTemp = Val(Mid(ActiveSheet.Names("_timestamp"), 2))

ActiveSheet.Name = Format(dateTemp, "MMM dd.hh.mm.ss")

End Sub


I am wonder if anyone can revise this so that when current Date
is returned the code dies; any changes made subsequently to the
worksheet the following day wouldn't change its value??



.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Time Stamp help

I usspect your TARGET is a date with hours minutes and seconds. To convert a
date/time number to just a date you can use the INT() function to remove the
fractional part of the number which is the hours/minutes/seconds which leaves
just the date.

Private Sub Worksheet_Change(ByVal Target As Range)

Dim dateTemp As Date

'remove hours minutes and seconds from targetand compare with date
if Int(target) < date()
ActiveSheet.Names.Add Name:="_timestamp", RefersTo:=Now()
dateTemp = Val(Mid(ActiveSheet.Names("_timestamp"), 2))

ActiveSheet.Name = Format(dateTemp, "MMM dd.hh.mm.ss")
end if
End Sub



"Gerard Sanchez" wrote:

Hi,

Currently I we have this VBA code that puts in the date and time
of last edit of the worksheet:


Private Sub Worksheet_Change(ByVal Target As Range)

Dim dateTemp As Date

ActiveSheet.Names.Add Name:="_timestamp", RefersTo:=Now()
dateTemp = Val(Mid(ActiveSheet.Names("_timestamp"), 2))

ActiveSheet.Name = Format(dateTemp, "MMM dd.hh.mm.ss")

End Sub


I am wonder if anyone can revise this so that when current Date
is returned the code dies; any changes made subsequently to the
worksheet the following day wouldn't change its value??



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default Time Stamp help (still need help)

'This code automatically names the worksheet as dates plus makes a ding
sound whenever a value in keypuch on specified cells.
'I had previously omitted some of the code (ding part) thinking that it
wasn't relevant to the question.

ActiveSheet.Name = Format(dateTemp, "MMM dd.hh.mm.ss") Then Exit Sub
does not work because there are other code that follows.

How do I make it so that after the DATE value is returned, the "date part of
the code" dies.

Here's the code:

__________________________

Private Declare Function sndPlaySound32 Lib "winmm.dll" Alias _
"sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long


Private Sub Worksheet_Change(ByVal Target As Range)

Dim dateTemp As Date

ActiveSheet.Names.Add Name:="_timestamp", RefersTo:=Now()
dateTemp = Val(Mid(ActiveSheet.Names("_timestamp"), 2))

ActiveSheet.Name = Format(dateTemp, "MMM dd.hh.mm.ss")

Set TargetRange = Range("H50:H51,H102:H103,H154:H155,H206:H207, _
H258:H259,H310:H311,H362:H363,H414:H415,H466:H467, H518:H519,_
H570:H571,H622:H623,H674:H675,H726:H727,H778:H779, H830:H831 ")

Set isect = Intersect(Target, TargetRange)

If Not isect Is Nothing Then
If isect.Count 1 Then Exit Sub
If Target.Row Mod 2 = 0 Then
If Target.Value = "" Or Target.Value = 0 Then Exit Sub
If Target.Value = Target.Offset(1, 0).Value Then
sndPlaySound32 "ding", 1&
End If
Else
If Target.Value = "" Or Target.Value = 0 Then Exit Sub
If Target.Value = Target.Offset(-1, 0).Value Then
sndPlaySound32 "ding", 1&
End If
End If
End If

End Sub

___________________________________
"Gerard Sanchez" wrote in message
...
Hi,

Currently I we have this VBA code that puts in the date and time
of last edit of the worksheet:


Private Sub Worksheet_Change(ByVal Target As Range)

Dim dateTemp As Date

ActiveSheet.Names.Add Name:="_timestamp", RefersTo:=Now()
dateTemp = Val(Mid(ActiveSheet.Names("_timestamp"), 2))

ActiveSheet.Name = Format(dateTemp, "MMM dd.hh.mm.ss")

End Sub


I am wonder if anyone can revise this so that when current Date
is returned the code dies; any changes made subsequently to the
worksheet the following day wouldn't change its value??





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 661
Default Time Stamp help (still need help)

Gerard

Add a couple of lines
If ActiveSheet.Name = Format(dateTemp, "MMM dd.hh.mm.ss") Then lDoIt = false
else lDoIt = True

if lDoIt = true
' Do your stuff when the sheet already exists
else
' Create your new sheet
endif

' Add any code that you run every time


"Gerard Sanchez" wrote:

'This code automatically names the worksheet as dates plus makes a ding
sound whenever a value in keypuch on specified cells.
'I had previously omitted some of the code (ding part) thinking that it
wasn't relevant to the question.

ActiveSheet.Name = Format(dateTemp, "MMM dd.hh.mm.ss") Then Exit Sub
does not work because there are other code that follows.

How do I make it so that after the DATE value is returned, the "date part of
the code" dies.

Here's the code:

__________________________

Private Declare Function sndPlaySound32 Lib "winmm.dll" Alias _
"sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long


Private Sub Worksheet_Change(ByVal Target As Range)

Dim dateTemp As Date

ActiveSheet.Names.Add Name:="_timestamp", RefersTo:=Now()
dateTemp = Val(Mid(ActiveSheet.Names("_timestamp"), 2))

ActiveSheet.Name = Format(dateTemp, "MMM dd.hh.mm.ss")

Set TargetRange = Range("H50:H51,H102:H103,H154:H155,H206:H207, _
H258:H259,H310:H311,H362:H363,H414:H415,H466:H467, H518:H519,_
H570:H571,H622:H623,H674:H675,H726:H727,H778:H779, H830:H831 ")

Set isect = Intersect(Target, TargetRange)

If Not isect Is Nothing Then
If isect.Count 1 Then Exit Sub
If Target.Row Mod 2 = 0 Then
If Target.Value = "" Or Target.Value = 0 Then Exit Sub
If Target.Value = Target.Offset(1, 0).Value Then
sndPlaySound32 "ding", 1&
End If
Else
If Target.Value = "" Or Target.Value = 0 Then Exit Sub
If Target.Value = Target.Offset(-1, 0).Value Then
sndPlaySound32 "ding", 1&
End If
End If
End If

End Sub

___________________________________
"Gerard Sanchez" wrote in message
...
Hi,

Currently I we have this VBA code that puts in the date and time
of last edit of the worksheet:


Private Sub Worksheet_Change(ByVal Target As Range)

Dim dateTemp As Date

ActiveSheet.Names.Add Name:="_timestamp", RefersTo:=Now()
dateTemp = Val(Mid(ActiveSheet.Names("_timestamp"), 2))

ActiveSheet.Name = Format(dateTemp, "MMM dd.hh.mm.ss")

End Sub


I am wonder if anyone can revise this so that when current Date
is returned the code dies; any changes made subsequently to the
worksheet the following day wouldn't change its value??





.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting the Time from a Date/Time Stamp agilek9 Excel Programming 2 November 20th 08 05:34 PM
time stamp Bally Excel Worksheet Functions 2 April 9th 08 07:40 PM
Comparing 2 files on date/time stamp, and based time difference do a subroutine [email protected] Excel Programming 1 September 28th 07 03:53 AM
Time Stamp Mike D. Excel Discussion (Misc queries) 2 May 25th 07 07:51 PM
time stamp a cell that doesn,t change when time stamping another RC Excel Programming 5 October 13th 05 02:52 AM


All times are GMT +1. The time now is 04:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"