+ Reply to Thread
Results 1 to 2 of 2

VBA to compare between two dates (Days)

Hybrid View

  1. #1
    Registered User
    Join Date
    12-13-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    68

    VBA to compare between two dates (Days)

    HI VBA Gurus,
    I have a spreadsheet with data from A17 to AG1000. Column B is used for inserting appropriate dates and I want to calculate number of days using VBA in column AH and the code I have been playing with is:-
    Sub Summary_Dates()
        Dim ws1 As Worksheet
        Dim Date1 As Date
        Dim Date2 As Date
        Dim DateDiff As Date
        Dim NumberDays As Integer
        Dim MyRng1 As Long
        Dim r As Long
        
        
        Set ws1 = Worksheets("CREDIT TRACKER")
        MyRng1 = ws1.Range("AG1000").Row
        For r = n To 1 Step -1
        If MyRng1 = "USE" Then
            Range("AH17").Value = ""
    
        ElseIf MyRng1 = "YES" Then
            Exit Sub
           
        Else
       
            Date1 = DateValue(Range("B17"))
    
    
            Date2 = Date
            DateDiff = Date2 - Date1
            NumberDays = Int(DateDiff)
            Range("AH17").Value = NumberDays + 1
        End If
        Next r
        
    End Sub
    Please can you help.

    Rgds

  2. #2
    Registered User
    Join Date
    01-24-2012
    Location
    Swindon, England
    MS-Off Ver
    Excel 2003
    Posts
    21

    Re: VBA to compare between two dates (Days)

    Hi

    Have you looked at the Help on the VBA function DateDiff? It includes an example for calculating the difference in days.

    Regards

    Dominic

+ 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. [SOLVED] Number of Days Between Dates but if no Date go to next and return # of Days
    By Bikeman in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-14-2012, 12:02 PM
  2. [SOLVED] Subtract Two Dates By The Number of Days, But Only Inlcude Work Days
    By ptho16 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-16-2012, 11:31 AM
  3. Replies: 2
    Last Post: 05-11-2012, 07:10 PM
  4. Compare two dates and possibly third if it exists to confirm <30 days
    By llamb in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-02-2012, 06:32 PM
  5. Replies: 6
    Last Post: 06-14-2010, 05:18 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