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
Report Generation of required month from consolidation
Month wise segregation irrespective of year
Retrieve the records based on date serial
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
Private Sub CommandButton1_Click()
Range("A5").AutoFilter
Range("A5").AutoFilter field:=1, Criteria1:=Range("E1").Value & Range("H1").Value, Operator:=xlFilterValues
End Sub
Retrieve records based on DATE RANGE
Private Sub CommandButton1_Click()
Range("A5").AutoFilter
If Range("K1").Value < Range("H1").Value Then
MsgBox "End Date should greaterthan Start Date"
Exit Sub
End If
Range("A5").AutoFilter
Range("A5").AutoFilter field:=1, Criteria1:=">=" & Range("H1").Value, _
Operator:=xlAnd, Criteria2:="<=" & Range("K1").Value
End Sub