For some reason, I cannot debug this code, the error is "Next without For"
I have looked at it forever and I can't figure out where I am missing an end if along the way. I would really appreciate a second hand of eyes.
Thanks!
I have looked at it forever and I can't figure out where I am missing an end if along the way. I would really appreciate a second hand of eyes.
Code:
Sub Filter_Dates()
Dim ws_Dest1 As Worksheet
Dim ws_Srce1 As Worksheet
Dim DCount As Double
Dim prdDate As String 'first set of dates (Yr-Period-Week format)
Dim insDate As String '2nd set of dates (same format)
Dim Dict_Year As New Scripting.Dictionary
Dim Dict_Period As New Scripting.Dictionary
Dim Dict_Week As New Scripting.Dictionary
Dim Dict_Dates As New Scripting.Dictionary
Dim Dict_FilterBP As New Scripting.Dictionary
Dim Dict_FilterNames As New Scripting.Dictionary
Dim dateKey As String
Dim yearKey As String
Dim periodKey As String
Dim weekKey As String
Dim temp_Date As String
Dim temp_year As String
Dim temp_period As String
Dim temp_week As String
Dim filterBP As String
Dim filterName As String
Application.ScreenUpdating = False
Application.EnableEvents = False
'Create a new BP list by looping through BPlist Sheet
Set ws_Dest1 = s_BPSummary
Set ws_Srce1 = s_BPList
DCount = ws_Srce1.Range("E65536").End(xlUp).Row
'filter/search fields
temp_year = ws_Dest1.Range("E2")
temp_period = ws_Dest1.Range("E3")
temp_week = ws_Dest1.Range("E4")
temp_Date = temp_year & "-" & temp_period & "-" & temp_week
For x = 3 To DCount
'001
If temp_year = "" And temp_period = "" And temp_week <> "" Then
If temp_week = Mid(ws_Srce1.Range("C" & x), 7, 1) Then
filterBP = ws_Srce1.Range("A" & x)
If Not Dict_FilterBP.Exists(filterBP) Then
Dict_FilterBP.Add filterBP, filterBP
End If
ElseIf temp_week = Mid(ws_Srce1.Range("D" & x), 7, 1) Then
filterName = ws_Srce1.Range("E" & x)
If Not Dict_FilterNames.Exists(filerName) Then
Dict_FilterNames.Add filterName, filterName
End If
End If
'010
ElseIf temp_year = "" And temp_period <> "" And temp_week = "" Then
If temp_period = Mid(ws_Srce1.Range("C" & x), 4, 2) Then
filterBP = ws_Srce1.Range("A" & x)
If Not Dict_FilterBP.Exists(filterBP) Then
Dict_FilterBP.Add filterBP, filterBP
End If
ElseIf temp_period = Mid(ws_Srce1.Range("D" & x), 4, 2) Then
filterName = ws_Srce1.Range("E" & x)
If Not Dict_FilterNames.Exists(filerName) Then
Dict_FilterNames.Add filterName, filterName
End If
End If
'011
ElseIf temp_year = "" And temp_period <> "" And temp_week <> "" Then
If temp_period = Mid(ws_Srce1.Range("C" & x), 4, 2) Then
filterBP = ws_Srce1.Range("A" & x)
If Not Dict_FilterBP.Exists(filterBP) Then
Dict_FilterBP.Add filterBP, filterBP
End If
ElseIf temp_period = Mid(ws_Srce1.Range("D" & x), 4, 2) Then
filterName = ws_Srce1.Range("E" & x)
If Not Dict_FilterNames.Exists(filerName) Then
Dict_FilterNames.Add filterName, filterName
End If
ElseIf temp_week = Mid(ws_Srce1.Range("C" & x), 7, 1) Then
filterBP = ws_Srce1.Range("A" & x)
If Not Dict_FilterBP.Exists(filterBP) Then
Dict_FilterBP.Add filterBP, filterBP
End If
ElseIf temp_week = Mid(ws_Srce1.Range("D" & x), 7, 1) Then
filterName = ws_Srce1.Range("E" & x)
If Not Dict_FilterNames.Exists(filerName) Then
Dict_FilterNames.Add filterName, filterName
End If
End If
'100
ElseIf temp_year <> "" And temp_period = "" And temp_week = "" Then
If temp_year = Mid(ws_Srce1.Range("C" & x), 1, 2) Then
filterBP = ws_Srce1.Range("A" & x)
If Not Dict_FilterBP.Exists(filterBP) Then
Dict_FilterBP.Add filterBP, filterBP
End If
ElseIf temp_year = Mid(ws_Srce1.Range("D" & x), 1, 2) Then
filterName = ws_Srce1.Range("E" & x)
If Not Dict_FilterNames.Exists(filerName) Then
Dict_FilterNames.Add filterName, filterName
End If
End If
'101
ElseIf temp_year <> "" And temp_period = "" And temp_week <> "" Then
If temp_year = Mid(ws_Srce1.Range("C" & x), 1, 2) Then
filterBP = ws_Srce1.Range("A" & x)
If Not Dict_FilterBP.Exists(filterBP) Then
Dict_FilterBP.Add filterBP, filterBP
End If
ElseIf temp_year = Mid(ws_Srce1.Range("D" & x), 1, 2) Then
filterName = ws_Srce1.Range("E" & x)
If Not Dict_FilterNames.Exists(filerName) Then
Dict_FilterNames.Add filterName, filterName
End If
If temp_week = Mid(ws_Srce1.Range("C" & x), 7, 1) Then
filterBP = ws_Srce1.Range("A" & x)
If Not Dict_FilterBP.Exists(filterBP) Then
Dict_FilterBP.Add filterBP, filterBP
End If
ElseIf temp_week = Mid(ws_Srce1.Range("D" & x), 7, 1) Then
filterName = ws_Srce1.Range("E" & x)
If Not Dict_FilterNames.Exists(filerName) Then
Dict_FilterNames.Add filterName, filterName
End If
End If
'110
ElseIf temp_year <> "" And temp_period <> "" And temp_week = "" Then
If temp_year = Mid(ws_Srce1.Range("C" & x), 1, 2) Then
filterBP = ws_Srce1.Range("A" & x)
If Not Dict_FilterBP.Exists(filterBP) Then
Dict_FilterBP.Add filterBP, filterBP
End If
ElseIf temp_year = Mid(ws_Srce1.Range("D" & x), 1, 2) Then
filterName = ws_Srce1.Range("E" & x)
If Not Dict_FilterNames.Exists(filerName) Then
Dict_FilterNames.Add filterName, filterName
End If
ElseIf temp_period = Mid(ws_Srce1.Range("C" & x), 4, 2) Then
filterBP = ws_Srce1.Range("A" & x)
If Not Dict_FilterBP.Exists(filterBP) Then
Dict_FilterBP.Add filterBP, filterBP
End If
ElseIf temp_period = Mid(ws_Srce1.Range("D" & x), 4, 2) Then
filterName = ws_Srce1.Range("E" & x)
If Not Dict_FilterNames.Exists(filerName) Then
Dict_FilterNames.Add filterName, filterName
End If
End If
'111
ElseIf temp_year <> "" And temp_period <> "" And temp_week <> "" Then
If temp_Date = ws_Srce1.Range("C" & x) Then
filterBP = ws_Srce1.Range("A" & x)
If Not Dict_FilterBP.Exists(filterBP) Then
Dict_FilterBP.Add filterBP, filterBP
End If
ElseIf temp_Date = ws_Srce1.Range("D" & x) Then
filterName = ws_Srce1.Range("E" & x)
If Not Dict_FilterNames.Exists(filerName) Then
Dict_FilterNames.Add filterName, filterName
End If
End If
Next x 'ERROR
ws_Dest1.Range("AA4:AA65536").ClearContents
'Unload Dictionaries on Destination page
DCount = ws_Dest1.Range("B65536").End(xlUp).Row
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
Thanks!