I am trying to write a nested if statement where a user select a timeframe and then the workbook is filtered based on the timeframe and copied to another workbook. Everything works fine except for some reason if the selection is "All Months, 2016 or 2017", then it skips the section where it copies to the other workbook. I am trying to see where i am missing the syntax. Below is part of the code with the nested if and attached is the full workbook with the entire code.
Thank you for your help.
Thank you for your help.
Code:
'select usedrange to copy
If Range("b7") = vbNullString Then 'it is blank
dataWB.Close SaveChanges:=False
ElseIf timeframe = "All Months" Then
With ActiveSheet
.Unprotect "ops"
.AutoFilterMode = False
.Columns("B:Z").EntireColumn.Hidden = False
.ListObjects("CJR_TBL").Range.AutoFilter Field:=1, Criteria1:="<>"
End With
ElseIf timeframe = "2016" Then
With ActiveSheet
.Unprotect "ops"
.AutoFilterMode = False
.Columns("B:Y").EntireColumn.Hidden = False
.ListObjects("CJR_TBL").Range.AutoFilter Field:=2, Criteria1:=timeframe
End With
ElseIf timeframe = "2017" Then
With ActiveSheet
.Unprotect "ops"
.AutoFilterMode = False
.Columns("B:Y").EntireColumn.Hidden = False
.ListObjects("CJR_TBL").Range.AutoFilter Field:=2, Criteria1:=timeframe
End With
Else
With ActiveSheet
.Unprotect "ops"
.AutoFilterMode = False
.Columns("B:Y").EntireColumn.Hidden = False
.ListObjects("CJR_TBL").Range.AutoFilter Field:=1, Criteria1:=timeframe
End With
'copy filtered data
Set tbl = ActiveSheet.AutoFilter.Range
tbl.Offset(1, 0).Resize(tbl.Rows.Count - 1, tbl.Columns.Count).Select
Selection.Copy
'activate generator workbook
currentWB.Activate
'activate master worksheet
TargetSh.Activate
TargetSh.Range(DestCell.Address).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Set DestCell = TargetSh.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
dataWB.Close False
End If
Next i
Application.StatusBar = False
ProgressBox.Hide
currentWB.Activate
Sheets("Generate").Activate
MsgBox "Reports have been generated successfully!", vbInformation
Sheets("CJR Tracking").Activate
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub