Advertisement

Advertisement

 Search Search for: Software DevelopmentAll Forums

# Excel macro time comparison

 Mzun
Member with 58 posts.
THREAD STARTER

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
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 - http://office.microsoft.com/en-us/ex...001228811.aspx

Andy
 meynardo
Junior Member with 1 posts.

Join Date: Sep 2011
Experience: Advanced
20-Sep-2011, 03:22 PM #3
Did you try:

=IF(A1>8,8,A1)

Or give us more details on how your spreadsheet is organized.
 henry48
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.
 techguy.org/1017784
As Seen On

WELCOME TO TECH SUPPORT GUY!

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.

 Tags excel, macro, time difference

THIS THREAD HAS EXPIRED.
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

WELCOME
FOLLOW US
You Are Using: