subtracting time between two cells vba

lordriel

Board Regular
Joined
Nov 1, 2005
Messages
68
Office Version
  1. 365
Platform
  1. Windows
I'm attempting to subtract a time in, say c9 from a time in c10 and get the difference in minutes, in vba.

I know this is a simple answer...Ji just don't know what it is.

Clearly I will need to know if the times are inverted (i.e. c10 time is earlier than c9 time), but that's also simple and I do know that answer.

Both cell output is hh:mm; I just need the difference between the two times, in minutes.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
The hours in Excel are given in relation to a day, so multiply by 24 hours, which is a day, and then by 60 minutes, which is an hour. That way you will get the difference in minutes:

Dante Amor
ABCDE
1
8
910:55:00 a. m.Minutes
1008:55:00 a. m.120
Hoja6
Cell Formulas
RangeFormula
E10E10=(C9-C10)*24*60
 
Upvote 0
Thank you for the quick response. But how do I code that in vba? I've tried what I thought would work. Then what I imagined would work. Then what I knew wouldn't work. No success.
 
Upvote 0
The result in cell E10:

VBA Code:
Sub dif()
  Range("E10").Value = (Range("C9").Value - Range("C10").Value) * 24 * 60
End Sub
 
Upvote 0
Solution
a tad of tweaking (I'm using variables and some other junk not worth detailing) and it's good to go!

Thank you!
 
Upvote 1

Forum statistics

Threads
1,215,390
Messages
6,124,667
Members
449,178
Latest member
Emilou

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