Dateadd calculation VBA problems

VBA-Noob

New Member
Joined
Dec 17, 2012
Messages
13
Hello,

Have an question abort mycket dateadd function.
X = 7
Code:
If DateAdd("h", 1, sheet1.cells(i, 6)) * 24 - x) > "" Then 
...
...
...
Can't get it work :(
 

Some videos you may like

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

steve the fish

Well-known Member
Joined
Oct 20, 2009
Messages
8,072
Office Version
365
Platform
Windows
What are you trying to do? It will always be >""
 

VBA-Noob

New Member
Joined
Dec 17, 2012
Messages
13
What are you trying to do? It will always be >""
What exactly are you expecting and what is happening?
Sorry, I as unclear.

What Im trying to do is. I column 6 I have time (like; 08:00, 23:00 etc). I want to use an dateadd "h" to control if any values are bigger then 07:00.
So what I basicly do is:

If DateAdd("h", 1, sheet1.Cells(I, 6)) * 24) - 7> "" Then

Because f I need to convert the time to decimal. If the time in column 7 is: 07:30 I want it to write:0,5 (07:30 - 07:00 (see sub in if-statement)).
 

WaterGypsy

Well-known Member
Joined
Jan 15, 2010
Messages
697
I think your problem is that the data in column 6 is a date - although it might look like a time on the surface so you are multiplying that date by 24 not just the time element
 

WaterGypsy

Well-known Member
Joined
Jan 15, 2010
Messages
697
Try something like
If Format(Range("a1"), "HH:MM") > "07:00" Then
imins = (Right(Format(Range("a1"), "HH:MM"), 2)) / 60
MsgBox imins
End If
 

VBA-Noob

New Member
Joined
Dec 17, 2012
Messages
13
Try something like
If Format(Range("a1"), "HH:MM") > "07:00" Then
imins = (Right(Format(Range("a1"), "HH:MM"), 2)) / 60
MsgBox imins
End If
Thanks for the answer but I cant get it work :(, the script is running OK now (b4 got error) but I don't get correct result. Have try in different ways but never comes in into the loop even when I have an time "bigger" then 07:00, have also try less then 07:00 then I got an Error.
When I used my If-statement I get the correct result after I format the cell but still got an error and can't run the whole sheet.

Thanks 4 help!
 

Watch MrExcel Video

Forum statistics

Threads
1,099,075
Messages
5,466,468
Members
406,484
Latest member
kaksolver

This Week's Hot Topics

Top