IF-statement and Cell Format (number)

VBA

New Member
Joined
Jan 19, 2009
Messages
39
:( This is just mean - my whole post disappeared! :banghead: :eek2: Ok, one more try...

I'm having a bit of trouble with date and time. Let's say my sheet looks like this:

dateandtime.jpg


I want to calculate the intermediate hours, thus between one given date/time (the time belongs to the date above) and the previous one. I figured I could just do
= (B1-C1)*24 + B2-C2
But apparently, date and time collide. Excell is quite confused which format to pick: it has to be either date or time...

I solved this by setting row 3, 4 and 5 on "general format" and using the following formula's
row 3) =B1-C1
row 4) =(B2-C2)*24 sometimes negative, *24 as the format time reduces to percentages of the day when set to general.
row 5) =B3*24+B4
This works.

I do wonder though, is it possible to make it into one if-statement? It seems a bit elaborate now...

Greetings.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
:rolleyes: It's that easy?!

Wow... it is...

Thanks a lot, I have been staring at this for an hour :biggrin: Amazing how easy it could have been :laugh:

Take care.
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,312
Members
452,634
Latest member
cpostell

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