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

Greetings,

I am stumped with this one. It must be in the time calculation, however, I
can't seem to make it work. What I have is a workbook with about twenty
years of computer data for several variables. They are displayed like this:

Time Data6/28/01 0:58 -0.499
6/28/01 1:58 -0.499
6/28/01 2:58 -0.499
6/28/01 3:58 -0.499
6/28/01 4:58 -0.499
6/28/01 5:58 -0.499
6/28/01 6:58 -0.499
6/28/01 7:58 -0.499


What I am trying to do is write a macro that inserts a blank row at 6:00 am,
12:00 pm, 6 pm and midnight.

Here is the code I have tried:

Dim SCC As Integer, SCR As Integer, WCR As Integer
Dim TST As Single, TST1 As Single

SCR = ActiveCell.Row ' SCR is Start Cell Row
SCC = ActiveCell.Column ' SCC is Start Cell Column
WCR = SCR ' initialize Work Cell Row from Start Cell Row

Do Until Cells(WCR, SCC) = ""

'TST = Hour(Cells(WCR, SCC)) + (Minute(Cells(WCR, SCC)) / 60)
'TST1 = (Hour(Cells(WCR, SCC)) * 60 + Minute(Cells(WCR, SCC))) / 60
'TST = Hour(Cells(WCR, SCC))
'TST1 = Hour(Cells(WCR + 1, SCC))

TST = ((Cells(WCR, SCC) - Fix(Cells(WCR, SCC)))) * 24
TST1 = ((Cells(WCR + 1, SCC) - Fix(Cells(WCR + 1, SCC)))) * 24


If TST <= 6 Then <<<<<<<<<<<<<<< This comparison doesn't work

ElseIf TST1 = 6 Then
Cells(WCR + 1, SCC).Select
Selection.EntireRow.Insert
End If
If TST <= 12 Then

ElseIf TST1 = 12 Then
Cells(WCR + 1, SCC).Select
Selection.EntireRow.Insert
End If

I have marked the comparison dat doesn't work. Actually they all don't work,
however with the data set I have attached, that one would be the only one
that could work. I have used watches on TST and TST1. They show values which
should process appropriately, however, they don't. As you can see I had
several attempts with converting the date to an hour, however, all were
unsuccessful. So I have to believe that it is something wrong in the way I
am comparing the hour and the 6, etc.

Any ideas on how to fix this would be appreciated.

Thanks in advance!

Ray


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Time comparison problem

Ray
it could be that you split the date and time.
then you could also have the windows daylight savings time UTC problem..
send me you marco and some real data, I'll look at it

Ray

"Ray Batig" wrote in message
ink.net...
Greetings,

I am stumped with this one. It must be in the time calculation, however, I
can't seem to make it work. What I have is a workbook with about twenty
years of computer data for several variables. They are displayed like

this:

Time Data6/28/01 0:58 -0.499
6/28/01 1:58 -0.499
6/28/01 2:58 -0.499
6/28/01 3:58 -0.499
6/28/01 4:58 -0.499
6/28/01 5:58 -0.499
6/28/01 6:58 -0.499
6/28/01 7:58 -0.499


What I am trying to do is write a macro that inserts a blank row at 6:00

am,
12:00 pm, 6 pm and midnight.

Here is the code I have tried:

Dim SCC As Integer, SCR As Integer, WCR As Integer
Dim TST As Single, TST1 As Single

SCR = ActiveCell.Row ' SCR is Start Cell Row
SCC = ActiveCell.Column ' SCC is Start Cell Column
WCR = SCR ' initialize Work Cell Row from Start Cell Row

Do Until Cells(WCR, SCC) = ""

'TST = Hour(Cells(WCR, SCC)) + (Minute(Cells(WCR, SCC)) / 60)
'TST1 = (Hour(Cells(WCR, SCC)) * 60 + Minute(Cells(WCR, SCC))) / 60
'TST = Hour(Cells(WCR, SCC))
'TST1 = Hour(Cells(WCR + 1, SCC))

TST = ((Cells(WCR, SCC) - Fix(Cells(WCR, SCC)))) * 24
TST1 = ((Cells(WCR + 1, SCC) - Fix(Cells(WCR + 1, SCC)))) * 24


If TST <= 6 Then <<<<<<<<<<<<<<< This comparison doesn't work

ElseIf TST1 = 6 Then
Cells(WCR + 1, SCC).Select
Selection.EntireRow.Insert
End If
If TST <= 12 Then

ElseIf TST1 = 12 Then
Cells(WCR + 1, SCC).Select
Selection.EntireRow.Insert
End If

I have marked the comparison dat doesn't work. Actually they all don't

work,
however with the data set I have attached, that one would be the only one
that could work. I have used watches on TST and TST1. They show values

which
should process appropriately, however, they don't. As you can see I had
several attempts with converting the date to an hour, however, all were
unsuccessful. So I have to believe that it is something wrong in the way I
am comparing the hour and the 6, etc.

Any ideas on how to fix this would be appreciated.

Thanks in advance!

Ray




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

There were a number of things wrong. I had to remove the 0.499 from the data
to get it to work. Your "if else" didn't make sense.

Sub splittime()


Dim SCC As Integer, SCR As Integer, WCR As Integer
Dim TST As Single, TST1 As Single

SCR = ActiveCell.Row ' SCR is Start Cell Row
SCC = ActiveCell.Column ' SCC is Start Cell Column
WCR = SCR ' initialize Work Cell Row from Start Cell Row

Do Until Cells(WCR + 1, SCC) = ""

'TST = Hour(Cells(WCR, SCC)) + (Minute(Cells(WCR, SCC)) / 60)
'TST1 = (Hour(Cells(WCR, SCC)) * 60 + Minute(Cells(WCR, SCC))) / 60
'TST = Hour(Cells(WCR, SCC))
'TST1 = Hour(Cells(WCR + 1, SCC))
MyTime = Cells(WCR, SCC)
Midnight = DateSerial(Year(MyTime), Month(MyTime), Day(MyTime))
TST = (MyTime - Midnight) * 24
NextTime = Cells(WCR + 1, SCC)
TST1 = (NextTime - Midnight) * 24


If Int(TST1 / 6) - Int(TST / 6) = 1 Then '<<<<<<<<<<<<<<< This
comparison doesn't work
Cells(WCR + 1, SCC).Select
Selection.EntireRow.Insert
WCR = WCR + 1
End If

WCR = WCR + 1
Loop
End Sub



"Ray Batig" wrote:

Greetings,

I am stumped with this one. It must be in the time calculation, however, I
can't seem to make it work. What I have is a workbook with about twenty
years of computer data for several variables. They are displayed like this:

Time Data6/28/01 0:58 -0.499
6/28/01 1:58 -0.499
6/28/01 2:58 -0.499
6/28/01 3:58 -0.499
6/28/01 4:58 -0.499
6/28/01 5:58 -0.499
6/28/01 6:58 -0.499
6/28/01 7:58 -0.499


What I am trying to do is write a macro that inserts a blank row at 6:00 am,
12:00 pm, 6 pm and midnight.

Here is the code I have tried:

Dim SCC As Integer, SCR As Integer, WCR As Integer
Dim TST As Single, TST1 As Single

SCR = ActiveCell.Row ' SCR is Start Cell Row
SCC = ActiveCell.Column ' SCC is Start Cell Column
WCR = SCR ' initialize Work Cell Row from Start Cell Row

Do Until Cells(WCR, SCC) = ""

'TST = Hour(Cells(WCR, SCC)) + (Minute(Cells(WCR, SCC)) / 60)
'TST1 = (Hour(Cells(WCR, SCC)) * 60 + Minute(Cells(WCR, SCC))) / 60
'TST = Hour(Cells(WCR, SCC))
'TST1 = Hour(Cells(WCR + 1, SCC))

TST = ((Cells(WCR, SCC) - Fix(Cells(WCR, SCC)))) * 24
TST1 = ((Cells(WCR + 1, SCC) - Fix(Cells(WCR + 1, SCC)))) * 24


If TST <= 6 Then <<<<<<<<<<<<<<< This comparison doesn't work

ElseIf TST1 = 6 Then
Cells(WCR + 1, SCC).Select
Selection.EntireRow.Insert
End If
If TST <= 12 Then

ElseIf TST1 = 12 Then
Cells(WCR + 1, SCC).Select
Selection.EntireRow.Insert
End If

I have marked the comparison dat doesn't work. Actually they all don't work,
however with the data set I have attached, that one would be the only one
that could work. I have used watches on TST and TST1. They show values which
should process appropriately, however, they don't. As you can see I had
several attempts with converting the date to an hour, however, all were
unsuccessful. So I have to believe that it is something wrong in the way I
am comparing the hour and the 6, etc.

Any ideas on how to fix this would be appreciated.

Thanks in advance!

Ray



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Time comparison problem

Joel,

Worked perfectly. Looks like I had some issues with serial dates as well.

Thanks!!

Ray

"Joel" wrote in message
...
There were a number of things wrong. I had to remove the 0.499 from the
data
to get it to work. Your "if else" didn't make sense.

Sub splittime()


Dim SCC As Integer, SCR As Integer, WCR As Integer
Dim TST As Single, TST1 As Single

SCR = ActiveCell.Row ' SCR is Start Cell Row
SCC = ActiveCell.Column ' SCC is Start Cell Column
WCR = SCR ' initialize Work Cell Row from Start Cell Row

Do Until Cells(WCR + 1, SCC) = ""

'TST = Hour(Cells(WCR, SCC)) + (Minute(Cells(WCR, SCC)) / 60)
'TST1 = (Hour(Cells(WCR, SCC)) * 60 + Minute(Cells(WCR, SCC))) / 60
'TST = Hour(Cells(WCR, SCC))
'TST1 = Hour(Cells(WCR + 1, SCC))
MyTime = Cells(WCR, SCC)
Midnight = DateSerial(Year(MyTime), Month(MyTime), Day(MyTime))
TST = (MyTime - Midnight) * 24
NextTime = Cells(WCR + 1, SCC)
TST1 = (NextTime - Midnight) * 24


If Int(TST1 / 6) - Int(TST / 6) = 1 Then '<<<<<<<<<<<<<<< This
comparison doesn't work
Cells(WCR + 1, SCC).Select
Selection.EntireRow.Insert
WCR = WCR + 1
End If

WCR = WCR + 1
Loop
End Sub



"Ray Batig" wrote:

Greetings,

I am stumped with this one. It must be in the time calculation, however,
I
can't seem to make it work. What I have is a workbook with about twenty
years of computer data for several variables. They are displayed like
this:

Time Data6/28/01 0:58 -0.499
6/28/01 1:58 -0.499
6/28/01 2:58 -0.499
6/28/01 3:58 -0.499
6/28/01 4:58 -0.499
6/28/01 5:58 -0.499
6/28/01 6:58 -0.499
6/28/01 7:58 -0.499


What I am trying to do is write a macro that inserts a blank row at 6:00
am,
12:00 pm, 6 pm and midnight.

Here is the code I have tried:

Dim SCC As Integer, SCR As Integer, WCR As Integer
Dim TST As Single, TST1 As Single

SCR = ActiveCell.Row ' SCR is Start Cell Row
SCC = ActiveCell.Column ' SCC is Start Cell Column
WCR = SCR ' initialize Work Cell Row from Start Cell Row

Do Until Cells(WCR, SCC) = ""

'TST = Hour(Cells(WCR, SCC)) + (Minute(Cells(WCR, SCC)) / 60)
'TST1 = (Hour(Cells(WCR, SCC)) * 60 + Minute(Cells(WCR, SCC))) / 60
'TST = Hour(Cells(WCR, SCC))
'TST1 = Hour(Cells(WCR + 1, SCC))

TST = ((Cells(WCR, SCC) - Fix(Cells(WCR, SCC)))) * 24
TST1 = ((Cells(WCR + 1, SCC) - Fix(Cells(WCR + 1, SCC)))) * 24


If TST <= 6 Then <<<<<<<<<<<<<<< This comparison doesn't work

ElseIf TST1 = 6 Then
Cells(WCR + 1, SCC).Select
Selection.EntireRow.Insert
End If
If TST <= 12 Then

ElseIf TST1 = 12 Then
Cells(WCR + 1, SCC).Select
Selection.EntireRow.Insert
End If

I have marked the comparison dat doesn't work. Actually they all don't
work,
however with the data set I have attached, that one would be the only one
that could work. I have used watches on TST and TST1. They show values
which
should process appropriately, however, they don't. As you can see I had
several attempts with converting the date to an hour, however, all were
unsuccessful. So I have to believe that it is something wrong in the way
I
am comparing the hour and the 6, etc.

Any ideas on how to fix this would be appreciated.

Thanks in advance!

Ray





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
Time Comparison Charles in Iraq Excel Programming 1 October 14th 06 11:40 AM
String Comparison using Like Problem sbowman Excel Programming 3 August 23rd 06 03:17 PM
Time comparison formula montagu Excel Discussion (Misc queries) 3 August 25th 05 03:37 PM
Time comparison Gixxer_J_97[_2_] Excel Programming 1 July 22nd 05 04:45 PM
Time/Data Comparison SharonP Charts and Charting in Excel 2 February 3rd 05 05:43 AM


All times are GMT +1. The time now is 09:49 PM.

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

About Us

"It's about Microsoft Excel"