Generate Date Range Reports

     

    Sub Generate_Report()
    Dim DataSh As Worksheet
    Set DataSh = ThisWorkbook.Sheets("Data Sheet")
    Maxrow = DataSh.Range("B" & Rows.Count).End(xlUp).Row
    Fy = DataSh.Range("H3").Value: Fm = DataSh.Range("H4").Value
    Fd = DataSh.Range("H5").Value
    FromDate = DateSerial(Fy, Fm, Fd)
    Symbol = DataSh.Range("I4").Value
    y = DataSh.Range("K3").Value: m = DataSh.Range("K4").Value:
    d = DataSh.Range("K5").Value
    Todate = DateSerial(y, m, d)
    If FromDate < Todate Then
    MsgBox "FromDate should be greater than ToDate"
    Exit Sub
    End If
    DataSh.Range("B4").CurrentRegion.AutoFilter
    DataSh.Range("B4").CurrentRegion.AutoFilter Field:=1, _
    Criteria1:="<=" & FromDate, Operator:=xlAnd, Criteria2:=">=" & Todate
    Lastrow = DataSh.Range("B" & Rows.Count).End(xlUp).Row
    DataSh.Range("B4:E" & Lastrow).SpecialCells(xlCellTypeVisible).Copy
    Dim sh As Worksheet
    Set sh = ThisWorkbook.Worksheets.Add(after:=
    ThisWorkbook.Sheets(Sheets.Count))
    sh.Activate
    sh.Range("B2").PasteSpecial (xlPasteAll)
    sh.Range("B2").CurrentRegion.Columns.AutoFit
    sh.Name = Fy & Fm & Fd & "<=" & y & m & d
    DataSh.Activate
    DataSh.Range("B4").CurrentRegion.AutoFilter
    MsgBox "Report Generated"
    End Sub



     

    Auto Filter - Date Range report

     

     

     

    Report Generation of Multiple months from consolidation

     

  • Select required months
  •  

     

     

    Report Generation of required month from consolidation

     

  • Though this code we can generate reports based on month and year, in a New Workbook
  •  

     

     

     

     

    Month wise segregation irrespective of year

     

  • Note: It takes some time to run the macro Please wait
  •  

     

     

    Retrieve the records based on date serial

     

  • Update the CELLS J3,J4,J5 Cells which denotes about FROM date
  •  

  • Update the CELLS L3,L4,L5 Cells which denotes about TO date
  •  

     

    Private Sub CommandButton1_Click()
    Range("J2").Value = DateSerial(Range("J5").Value, Range("j4").Value, Range("j3").Value)
    Range("L2").Value = DateSerial(Range("L5").Value, Range("L4").Value, Range("L3").Value)
    Sheets("Sheet3").UsedRange.Clear
    e = Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Row
    last = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row
    For q = 2 To last
    Sheets("Sheet2").Activate
    d = Range("B" & q).Value
    If (d >= Range("J2").Value And d <= Range("L2").Value) Then
    Range(Cells(q, 1), Cells(q, 7)).Select
    Selection.Copy Destination:=Sheets("Sheet3").Range("A" & e)
    End If
    e = Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Row + 1
    Application.StatusBar = q
    Next
    End Sub

     

     

    Based On Date

     

  • Filter the Data Based on a DATE
  •  

     

    How to use this template:

     

  • Update START DATE in H1 Cell
  •  

  • Update the Required Symbol in E1 Cell
  •  

  • Click on GENERATE REPORT Command Button to retrieve results
  •  

  • Click on RESULT IN NEW SHEET, if Filtered Data wants to display by creating new worksheet, in this workbook
  •  

  • Click on RESULT IN NEW WORKBOOK, if Filtered Data wants to display by creating new workbook
  •  

    Private Sub CommandButton1_Click()
    Range("A5").AutoFilter
    'Mention the cirteria in E1 and Date in H1 Cells respectively
    Range("A5").AutoFilter field:=1, Criteria1:=Range("E1").Value & Range("H1").Value, Operator:=xlFilterValues
    End Sub

     

     

    Retrieve records based on DATE RANGE

     

     

  • Update START DATE in H1 Cell and End Date in K1 Cell
  •  

  • Paste your required data from A5 Cell
  •  

  • Click on GENERATE REPORT Command Button to retrieve results
  •  

  • Click on RESULT IN NEW SHEET, if Filtered Data wants to display by creating new worksheet, in this workbook
  •  

  • Click on RESULT IN NEW WORKBOOK, if Filtered Data wants to display by creating new workbook
  •  

     

    Private Sub CommandButton1_Click()
    Range("A5").AutoFilter
    'Mentioned Datavalidation in K1 & H1 cells through offset formulas
    If Range("K1").Value < Range("H1").Value Then
    MsgBox "End Date should greaterthan Start Date"
    Exit Sub
    End If
    Range("A5").AutoFilter
    'Mention the dates in cells of H1 & K1
    Range("A5").AutoFilter field:=1, Criteria1:=">=" & Range("H1").Value, _
    Operator:=xlAnd, Criteria2:="<=" & Range("K1").Value
    End Sub