That was quite a bit. Create a new sheet named "Output" for the output result:
Sub Create_Summary()
Dim dOrders As Object: Set dOrders = CreateObject("Scripting.Dictionary")
Dim ws1 As Worksheet: Set ws1 = Sheets("Sample_Conditions")
Dim ws3 As Worksheet: Set ws3 = Sheets("Voter List")
Dim ws4 As Worksheet: Set ws4 = Sheets("Output") 'a new sheet that you need to create. Feel free to change the sheet name here
Dim arrVoters As Variant, k As Variant, arrOrders As Variant
Dim i As Long, ii As Long
Dim rVoter As Range
Application.ScreenUpdating = False
If Not Evaluate("=ISREF('" & ws4.Name & "'!A1)") Then
MsgBox ("You didn't make an output sheet")
Exit Sub
Else
ws1.Range("A1").EntireRow.Copy ws4.Range("A1")
End If
arrVoters = ws3.Range("A2:A" & ws3.Range("A" & Rows.Count).End(xlUp).Row)
arrOrders = ws1.Range("A2:A" & ws1.Range("A" & Rows.Count).End(xlUp).Row)
For i = LBound(arrOrders, 1) To UBound(arrOrders, 1)
dOrders(arrOrders(i, 1)) = 1
Next i
For Each k In dOrders.keys
With ws1
.AutoFilterMode = False
.Range("A1:A" & ws1.Range("A" & Rows.Count).End(xlUp).Row).AutoFilter 1, k
For ii = LBound(arrVoters, 1) To UBound(arrVoters, 1)
Set rVoter = .Range("C1:C" & ws1.Range("C" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeVisible).Find(arrVoters(ii, 1), , xlValues, xlWhole, , xlPrevious)
If Not rVoter Is Nothing Then
If .Range("E" & rVoter.Row).Value > .Range("B" & rVoter.Row).Value Then 'met
rVoter.EntireRow.Copy ws4.Range("A" & Rows.Count).End(3)(2)
ws4.Range("F" & Rows.Count).End(3)(2).Value = "Met"
Else 'missed
rVoter.EntireRow.Copy ws4.Range("A" & Rows.Count).End(3)(2)
ws4.Range("F" & Rows.Count).End(3)(2).Value = "Missed"
End If
Else 'no vote
.Range("C2:C" & ws1.Range("C" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeVisible).Cells(1, 1).EntireRow.Copy ws4.Range("A" & Rows.Count).End(3)(2)
ws4.Range("B" & ws4.Range("A" & Rows.Count).End(xlUp).Row, "D" & ws4.Range("A" & Rows.Count).End(xlUp).Row).ClearContents
ws4.Range("C" & Rows.Count).End(3)(2).Value = arrVoters(ii, 1)
ws4.Range("F" & Rows.Count).End(3)(2).Value = "No Vote"
End If
Next ii
.ListObjects("Table1").Range.AutoFilter Field:=1
End With
Next k
Application.ScreenUpdating = True
End Sub
Bookmarks