Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Excel Date/Time problem

I have written a macro designed to change the color and
bold all values of 40 seconds and above in a column. The
column looks like this:

0:00:02
0:00:56
0:00:03
etc.

For a number of reasons, I cannot use conditional
formatting and am attempting to do this via code.

Here is the macro:

Sub Summary1()

Dim test_name As String
Dim mynumber As Date

test_name = ActiveWorkbook.Name
mynumber = "0:00:39"

ActiveWorkbook.SaveAs Filename:="Z:\Excel\" & test_name
& " - Sum 1 test.xls"

Columns("E:E").Select
Selection.Delete Shift:=xlToLeft
Columns("K:K").Select
Selection.Delete Shift:=xlToLeft
Columns("L:O").Select
Selection.Delete Shift:=xlToLeft

Range("K3").Select

Do Until ActiveCell.Value = ""
If ActiveCell.Value mynumber Then
Selection.Font.ColorIndex = 3
Selection.Font.Bold = True
End If

ActiveCell.Offset(1, 0).Select

Loop

End Sub

The macro works and changes all cells with 00:00:40 and
above. However, it also includes cells with a value of
00:00:39 for some reason. As you might guess, I tried
changing the value of the mynumber variable to 0:00:40.
When I did this, only values of 0:00:41 and higher were
changed and cells with the actual value of 0:00:40 were
ignored. I am mystefied.



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Excel Date/Time problem

0:00:39 = .000451388888889
0:00:40 = .000462962962963

half the numbers between those two values will display as 0:00:39 and half
as 0:00:40 (and also between 38 and 39 seconds). Any test of equality will
fail if they are not exactly equal. Using could result in mixed results.

Perhaps use a test like

If cDate(format(ActiveCell.Value2,"hh:mm:ss")) mynumber Then


--
Regards,
Tom Ogilvy


"Demian Valle" wrote in message
...
I have written a macro designed to change the color and
bold all values of 40 seconds and above in a column. The
column looks like this:

0:00:02
0:00:56
0:00:03
etc.

For a number of reasons, I cannot use conditional
formatting and am attempting to do this via code.

Here is the macro:

Sub Summary1()

Dim test_name As String
Dim mynumber As Date

test_name = ActiveWorkbook.Name
mynumber = "0:00:39"

ActiveWorkbook.SaveAs Filename:="Z:\Excel\" & test_name
& " - Sum 1 test.xls"

Columns("E:E").Select
Selection.Delete Shift:=xlToLeft
Columns("K:K").Select
Selection.Delete Shift:=xlToLeft
Columns("L:O").Select
Selection.Delete Shift:=xlToLeft

Range("K3").Select

Do Until ActiveCell.Value = ""
If ActiveCell.Value mynumber Then
Selection.Font.ColorIndex = 3
Selection.Font.Bold = True
End If

ActiveCell.Offset(1, 0).Select

Loop

End Sub

The macro works and changes all cells with 00:00:40 and
above. However, it also includes cells with a value of
00:00:39 for some reason. As you might guess, I tried
changing the value of the mynumber variable to 0:00:40.
When I did this, only values of 0:00:41 and higher were
changed and cells with the actual value of 0:00:40 were
ignored. I am mystefied.





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
Converting text format of time/date into Excel time/date for subtr YY san.[_2_] Excel Worksheet Functions 6 February 25th 10 08:27 AM
Date / Time problem mc Excel Discussion (Misc queries) 4 September 5th 08 09:11 PM
Date & Time problem ckiraly Excel Worksheet Functions 2 August 15th 05 01:13 PM
Ugh..another time and date problem...HELP Sandy Excel Worksheet Functions 4 July 29th 05 05:37 PM
Excel static current date/time problem hpmted Excel Worksheet Functions 1 March 30th 05 09:12 PM


All times are GMT +1. The time now is 11:46 PM.

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"