Good day. I would like to ask help regarding conditional setup. So I have a dates that will be filtered based on the condition and will copy paste it. My problem right now is if the condition dates are not available, it will copy all the information. So if the condition dates are not available, it will move to the next Sheet. Thank you in advance.
Code:
Sub Consolidate()Dim cRow As Integer
Dim sRow As Integer
Dim lngStart As Long, lngEnd As Long
lngStart = Range("K1").Value
lngEnd = Range("L1").Value
For i = 2 To Sheets.Count
Sheets(i).Activate
Range("A:G").AutoFilter field:=1, _
Criteria1:=">=" & lngStart, _
Operator:=xlAnd, _
Criteria2:="<=" & lngEnd
cRow = Application.WorksheetFunction.CountA(Range("A:A"))
Cells(2, 7) = Sheets(i).Name
Sheets(i).Range("G2").Copy
Sheets(i).Range("G2:G" & cRow).PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False
Sheets(i).Range("A2:G" & cRow).SpecialCells(xlCellTypeVisible).Copy
Sheets(1).Activate
sRow = Application.WorksheetFunction.CountA(Range("A:A")) + 1
Sheets(1).Range("A" & sRow).PasteSpecial Operation:=xlNone, SkipBlanks:=False
Next i
End Sub