Calculate Weeks Between two Dates in Excel VBA

Calculate weeks Between two Dates

Calculate weeks Between two Dates in Excel VBA using VBA formulas. We use DateDiff VBA Function to determine the number of weeks between two dates. In order to calculate number of weeks between two dates we need start date and end date. It returns an integer value as a result. We use DateDiff function in Excel to perform same task in Excel.

Macro to Calculate Number of weeks Between two Dates in Excel VBA

Let us see the macro to count number of weeks Difference Between two Dates in Excel VBA.

'Calculate weeks Between two Dates in Excel VBA
Sub VBA_Calculate_weeks_Between_Two_Dates()
    
    'Variable declaration
    Dim sDate As Date, eDate As Date
    Dim iValue As Integer
    
    'Start Date
    sDate = "10-Jan-2020"
    
    'End Date
    eDate = "10-Mar-2020"
    
    iValue = DateDiff("w", sDate, eDate)
    
    'Display output on the screen
    MsgBox "The number of weeks between two dates : " & iValue, vbInformation, "Weeks Between Two Dates"
    
End Sub

Here is the output screen shot of above specified macro.
Calculate Weeks Between two Dates

Instructions to Run VBA Macro Code or Procedure:

You can refer the following link for the step by step instructions.

Instructions to run VBA Macro Code

Other Useful Resources:

Click on the following links of the useful resources. These helps to learn and gain more knowledge.

VBA Tutorial VBA Functions List VBA Arrays VBA Text Files VBA Tables

VBA Editor Keyboard Shortcut Keys List VBA Interview Questions & Answers Blog

Leave a Comment