Software Lab Generate Sequential Dates
Description:
This set of VBA codes can be used to generate sequential dates. Very useful for getting a list of future sequential dates from a start date. Further use can be applied by applying perhaps weekday filter or specific days on these sequential dates.
Code:
Sub DateLoop()

Dim i As Integer
Dim j As Date
Dim wb As Workbook
Dim ws As Worksheet
Dim rng As Range



'Set wb = Workbooks("StoredProcedure.xlsm")
Set wb = ActiveWorkbook

'j = Range("E1").Value
j = "2018-01-31"


With wb
    .Activate
    Worksheets("Sheet1").Select
    
    
    If ActiveSheet.FilterMode Then ActiveSheet.AutoFilterMode = False
    
    Columns("A:B").Clear

             
    For i = 1 To 90
    
        Cells(i, 1).Value = j + i
        Cells(i, 2).Value = Format(Cells(i, 1), "dddd")
    
    Next i
    
    Range("A1:B1").Insert
    
    Range("A1").Select
        With Selection
            .Value = "Date"
            .ColumnWidth = 15
        End With
        
    Range("B1").Select
        With Selection
            .Value = "Day"
            .ColumnWidth = 15
        End With

Set rng = ActiveSheet.Range("A1:B31")
    
'Turn on filter if not already turned on
  If ActiveSheet.AutoFilterMode = False Then rng.AutoFilter
      
'Filter Specific Days
  rng.AutoFilter Field:=2, Criteria1:=Array( _
    "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"), Operator:=xlFilterValues
    
End With



End Sub

Procedures:
  1. Insert a new module (VBA) in your excel file.
  2. Copy and paste the above codes into the module.
  3. With the start date, you may update the “j” value directly in the code.