Get Next Date using VBA Functions

VBA Get Next Date

Get Next Date using VBA Functions

Get Next Date using Excel VBA Functions. Date plays an important major role in data analysis to summarize data, to create graphs and dashboards based on date. We also format date using format function in multiple ways.

Macro to find Next Date using VBA

Let us see the procedure how to find Next Date using VBA Date and Format functions.

'Procedure to Get Next Date
Sub VBA_Next_Date()
    
    'Variable declaration
    Dim dDate As Date
    
    'Get next date
    dDate = DateAdd("d", 1, Date)
    
    'Display next date
    MsgBox "If today's date is " & Date & vbCrLf & _
    "then the next date is :" & dDate, vbInformation, "Get Next Date"
    
End Sub

Here is the output screen shot of the above macro procedure.
VBA Get Next Date

Format Date in different ways:

We have different format methods to format Date. You can find output in an immediate window.

'Format Date
Sub VBA_Format_Date()
    
    'Variable declaration
    Dim dDate As String
    
    dDate = Format(Date, "ddmmyy")
    Debug.Print dDate
    
    dDate = Format(Date, "ddmmyyyy")
    Debug.Print dDate
    
    dDate = Format(Date, "ddmmmyyyy")
    Debug.Print dDate
    
    dDate = Format(Date, "ddmmmyy")
    Debug.Print dDate
    
    dDate = Format(Date, "dd/mmm/yy")
    Debug.Print dDate
    
    dDate = Format(Date, "dd-mmm-yy")
    Debug.Print dDate
    
    dDate = Format(Date, "dddd ddmmmyy")
    Debug.Print dDate
    
    dDate = Format(Date, "dddd dd mmm yy")
    Debug.Print dDate
        
End Sub

Output screenshot:

Here is the output screenshot for your reference.
VBA Format Date

Instructions to use Macro:

  • Open Visual Basic Editor by clicking Alt +F11
  • Goto code window by clicking F7
  • Copy any of the above specified procedure or macro
  • Paste above copied code in code window
  • Run macro by clicking F5 or Run command
  • You can see ouput on the screen
  • Find specified output screenshot above.

Related VBA Functions used in this article:

We have used Date,DateAdd and Format VBA functions. Click on below specified links to learn more about VBA functions.

VBA Date Function VBA Format Function VBA DateAdd Function






Leave a Comment

Your email address will not be published. Required fields are marked *