PDA

View Full Version : Read time 00:00:00 > 23:59:00 rather than <



sdwards
02-23-2011, 04:19 PM
Ok, give up :banghead:

I'm trying to copy a value from a table depending on the time. So simply table is (r=row, c=column):

....1....................2..............3
1 Date..............Time..........Cost
2 11/11/2007...23:59:00.......$40
3 11/12/2007...00:00:00.......$40

(Obviously without the full stops)

I have a statement:
If Cells(r,2)<Cells(r+1,2) then
Copy.Cells blah blah blah

VB is reading the cell(3,2) < cell(2,2) since excel is taking the numeric value, I think. The problem is, I don't know how to make VB realise cell(3,2) > cell(2,2) since this is the next day. I have gone through all the objects in the DateTime and but to no avail. :help

Help would be much appreciated,
Scott

Blade Hunter
02-23-2011, 06:34 PM
Why not minus a second of it when you read it?

p45cal
02-23-2011, 07:38 PM
Assuming the date column is just a pure date and has no time element (ie. it's an integer) then
if (cells(r,1)+cells(r,2))>(cells(r+1,1)+cells(r+1,2)) then blah blah

mdmackillop
02-24-2011, 06:43 AM
Hi Scott,
Welcome to VBAX
You can post a workbook using Manage Attachments in the Go Advanced reply section.

IBihy
02-24-2011, 10:02 AM
Hello,

a timestamp (date and time together) is a number in the computer's internal clock. Date formatting and time formatting are just that, formatting.

First of all, you should use the DateTime data type as a whole, and not the time as a string. Well, what's input to the time checking in you WB?

If you use this, you can split it into the date part and the time part with built-in functions of VBA.

How about supplying a sample?

Isabella