Posted to microsoft.public.excel.programming
|
|
Glitch in code some where, i think ?
Tom,
Value did the same and jumped to 11 July 2006 when supposedly adding 7 days
to 31 October 2006???
Corey....
"Tom Ogilvy" wrote in message
...
If the cell actually contains a date serial number and not a string/text
which looks a date, then it should make no difference how it is formatted.
I suspect if you qualify your ranges (particularly if this is in a sheet
module rather than a general module) and use Value2, it will correct the
problem.
Sub callUpdates()
Sheets("Enter - Exit").Select ' Sheet name
Dim ws As Worksheet
Application.ScreenUpdating = False
For Each ws In ActiveWorkbook.Worksheets
With ws.Range("E2") ' Date value displayed a 31 October 2006
if isdate(.Value) then
.Value2 = .Value2 + 7
else
msgbox "Cell E2 on " & ws.name & " is not a date"
End if
End with
Next
Sheets("Enter - Exit").Select
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
--
Regards,
Tom Ogilvy
"Corey" wrote in message
...
How to i code that format ?
"alondon" wrote in message
...
Corey,
There is no error in the code, but the format of the E2 cell on each
sheet must be custom format "dd mmmm yyyy" to work consistently. Note,
you were wise to always use the European dating convention.
Allan P. London, CPA
"Corey" wrote in message
...
Have posted this eror before with no replies.
################################################## ###########
Sub callUpdates()
Sheets("Enter - Exit").Select ' Sheet name
Dim ws As Worksheet
Application.ScreenUpdating = False
For Each ws In Application.Worksheets
ws.Select
With Range("E2") ' Date value displayed a 31 October 2006
.Value = Range("E2").Value + 7 ' Should add 7 days to currently
displayed date value
End With
Next
Sheets("Enter - Exit").Select
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
################################################## ##########
The above code suppose to add 7 days to a date value in Cell E2,
Yet sometimes it works fine,
yet other times it jumps 6 months backwards from 31 October 2006 - 11
July 2006.
Why ?
Is there an error in the code?
Corey....
|