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 :(
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
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)).
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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!
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top