There's no such thing as a stupid question, but they're the easiest to answer.


Software Development Software Development
Search Search
Search for:
Tech Support Guy > > >

Excel macro time comparison


Mzun's Avatar
Mzun Mzun is offline
Member with 58 posts.
Join Date: Jun 2011
15-Sep-2011, 06:37 AM #1
Excel macro time comparison
I'm trying to write a macro that calculates the difference between two times. If the difference is greater that 8 hours then the diffence is set equal to 8 hours. My code currently looks like this but it doesn't work (cell A1 stores the difference between the two times).

If Range("A1").Value > 8 Then
Range("A1").Value = 8
End If

Any Suggestions?
andythepandy's Avatar
andythepandy andythepandy is offline
Computer Specs
Member with 367 posts.
Join Date: Jul 2006
Location: England
Experience: Intermediate to Advanced
15-Sep-2011, 09:00 AM #2
Take a look at the datediff function -

meynardo's Avatar
meynardo meynardo is offline
Junior Member with 1 posts.
Join Date: Sep 2011
Experience: Advanced
20-Sep-2011, 03:22 PM #3
Did you try:


Or give us more details on how your spreadsheet is organized.
henry48's Avatar
henry48 henry48 is offline
Junior Member with 2 posts.
Join Date: Sep 2011
Location: united states
Experience: henry48
28-Sep-2011, 11:09 AM #4
A macro is a series of commands that perform a specific task in Excel. To save time when performing common operations you can create a macro with the macro recorder that can be run whenever you need to perform the task. This tutorial describes step by step how to create a simple macro in Excel using the macro recorder.
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

excel, macro, time difference

Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools

You Are Using: Server ID
Trusted Website Back to the Top ↑