I am new to VBA and I am struggling to define filters by which my data should be copied to an overview sheet. I would like for all rows to appear that contain the current month plus all dates in the next three months. My current date format is MMMM YYYY (Oct 20 etc.). This is my current code, it works very well, but I dont want to update it each month. I tried a few codes I found on here but nothing worked, maybe because I dont use Autofilter or because my date format is a bit weird? The relevant code part starts from:
Any help would be appreciated! Thanks!
VBA Code:
For i = 1 To nRows
VBA Code:
Public Sub CopyRows()
Dim ws As Worksheet
Dim s_Main As String
Dim nRow As Long
Dim Last_row As Long
Dim i As Long
Dim Table As Variant
s_Main = "Overview"
Last_row = Worksheets(s_Main).Cells(Rows.Count, 1).End(xlUp).Row
Worksheets(s_Main).Range("A2:P" & Last_row).ClearContents
For Each ws In Worksheets
If ws.Name = s_Main Then
GoTo Change_ws
Else
nRows = ws.Cells(Rows.Count, 1).End(xlUp).Row
ReDim Table(nRows, 16)
Table = ws.Range("A1:P" & nRows)
For i = 1 To nRows
If Table(i, 2) = "01.09.2020" Or Table(i, 2) = "01.10.2020" Or Table(i, 2) = "01.11.2020" Then
Last_row = Worksheets(s_Main).Cells(Rows.Count, 1).End(xlUp).Row
ws.Range("A" & i & ":P" & i).Copy Worksheets(s_Main).Range("A" & Last_row)(2)
End If
Next i
End If
Change_ws:
Next ws
End Sub
Any help would be appreciated! Thanks!