I can't seem to spot the error in my code when I changed my Sheets(1) to Sheet1 in my code so that way I could have multiple sheets not included in the code. This code takes everything from Sheet1 and moves it to sheets i call ABQ 2015 & ABQ 2016 when it finds proper dates dates. I'm getting no errors but nothing is moving.
Sub CopyABQ()
Dim ary As Variant, yr As Long
ary = Array("2015", "2016")
For i = LBound(ary) To UBound(ary)
Select Case ary(i)
Case "2015"
x = #1/1/2015#: y = #12/31/2015#
Case "2016"
x = #1/1/2016#: y = #12/31/2016#
End Select
Sheet1.UsedRange.AutoFilter 12, ">=" & x, xlAnd, "<=" & y
If Sheets("ABQ " & ary(i)).Range("A5") = "" Then
Sheet1.UsedRange.Offset(1).Copy Sheets("ABQ " & ary(i)).Range("A5")
Else
Sheet1.UsedRange.Offset(1).Copy Sheets("ABQ " & ary(i)).Cells(Rows.Count, 1).End(xlUp)(2)
End If
Sheet1.AutoFilterMode = False
Sheets("ABQ " & ary(i)).Columns.AutoFit
Next
End Sub
Bookmarks