+ Reply to Thread
Results 1 to 5 of 5

Subtracting Dates/Times

Hybrid View

  1. #1
    Registered User
    Join Date
    09-19-2008
    Location
    GB
    Posts
    2

    Subtracting Dates/Times

    Hi,
    I just started learning VBA in the last few weeks and I am really stock/lost. Please can you help. I am looking for a VBA code that can subtarct two dates/times….subtract columA from columB.....

    ColumB is 27/06/2008 23:38:01
    ColumA is 27/06/2008 23:35:10

    if possible, how do I get the differece in minutes i.e. 3 min

    Thank you for your help

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    Hi SKZag, welcome to the forum.

    Adjust this code as needed to reference your cells:
    Range("C1").Value = CInt((Range("B1").Value - Range("A1").Value) * 1440)

  3. #3
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    'my previous post was erroneus... I apologize*
    Last edited by antoka05; 09-26-2008 at 04:39 AM.

  4. #4
    Registered User
    Join Date
    09-19-2008
    Location
    GB
    Posts
    2
    Hi Paul,

    Thank you for your reply.
    Paul, I adjusted your code according to my needs, however I am still getting the following error “Runtime error “13” Type mismatch”.
    Actually, the data changes from day to day and the formula is Qi = Pi - Oi
    The code is below:
    >>>
    Dim NumberRows As Integer
    Sub Subtract ()
    Range("P1").Select
    Selection.End(xlDown).Select
    NumberRows = ActiveCell.Row

    For i = NumberRows To 1 Step -1
    Cells(i, 17).Value = CInt((Cells(i, 16).Value - Cells(i, 15).Value)*1440)
    Next i
    End Sub
    >>>
    Thank you very much for you help.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Please read the Forum Rules and then edit your post to wrap your code with Code Tags.
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 08-02-2008, 05:43 PM
  2. Subtracting - variable conditions
    By Bodz in forum Excel General
    Replies: 4
    Last Post: 07-26-2008, 12:55 PM
  3. Subtracting datetime cells
    By anj in forum Excel General
    Replies: 2
    Last Post: 09-27-2007, 06:57 PM
  4. Counting text in range subtracting from par
    By desk.doc in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-19-2007, 02:29 PM
  5. Subtracting to a blank cell
    By jephrey_dal in forum Excel General
    Replies: 4
    Last Post: 05-27-2007, 10:40 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1