Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 27th, 2009, 03:07 PM
Authorized User
 
Join Date: May 2009
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Default Add minutes to a time calculation

I have a time calculation (end time minus start time) that is not working quite right. It is used in time logs to pay people.

If a time entry is 8:00am - 11:00am, it will return 3 hours.

But if it is multiple entries, the people type entries like the following:
8:00am - 9:15am
9:16am - 10:15am
10:16am - 11:00am
It will return something less than 3 hours even though contractors believe that all minutes are seemingly accounted for.

I would like to add 1 minute to each calculation and do not know how to add minutes in time in a formula.

The code I now use in a macro is: (This is part of a loop)
Dim lLastGRow As Long
lLastGRow = ActiveSheet.Cells(Rows.Count, "G").End(xlUp).Row
Range("H2:H" & lLastGRow).FormulaR1C1 = "=(RC[-1]-RC[-2])*24"

Essentially, the cursor is in the column that needs the total and it subtracts the entry 2 columns to the left from the entry 1 column to the left. Bot of those cells are in a time format. I want to just add 1 minute to each calculation. (Yes, it will ultimately add a few minutes to people's pay, but overall the amount is meaningless; what I cannot do is underpay by a minute.)

How do I add that 1 minute in the formula? I cannot just add +1, I cannot just add +:01. I do not want to put 1 minute in a cell somewhere and always add in that cell. There must be an easier way. Actually, I guess I would not know quite how to put a 1 minute entry in a cell and add it either.

Help?
 
Old September 28th, 2009, 10:04 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

Can you try the following in VBA

dateadd("n",1,now)

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
 
Old September 28th, 2009, 10:04 AM
Friend of Wrox
 
Join Date: Feb 2007
Posts: 163
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Time literals in VBA are enclosed with # signs and must be appropriately stated. #12:00 AM# is the same as adding 0 to whatever time you already have so try adding as such:

Code:
Dim dTime As Date
dTime =Now()
msgbox dTime & " + 1 Minute is " & dTime + #12:01 AM#
Hope this helped point in the right direction.





Similar Threads
Thread Thread Starter Forum Replies Last Post
convert time to minutes stolte XSLT 3 November 21st, 2008 04:12 AM
Calculate time (minutes) between two times rtr1900 Classic ASP Basics 18 January 2nd, 2008 03:06 PM
time calculation hozyali Beginning PHP 2 April 9th, 2007 08:02 AM
Time Calculation surendran MySQL 1 June 24th, 2006 01:38 PM
Time calculation rdfernandez Access VBA 6 March 24th, 2005 11:51 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.