Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Enable Microsoft scripting library first via Tools > References > Microsoft Scripting Library/Runtime
- Public Function CountUnique(rng As Range) As Integer
- Dim dict As Dictionary
- Dim cell As Range
- Set dict = New Dictionary
- For Each cell In rng.Cells
- If Not dict.Exists(cell.Value) Then
- dict.Add cell.Value, 0
- End If
- Next
- CountUnique = dict.Count
- End Function
- Sub ParticipantSort()
- 'Sorts participants by fundraising level and provides segmented results.
- Dim SheetName As String, number As Double
- Application.ScreenUpdating = False
- number = Application.CountA(Columns(1))
- SheetName = Format(Date, "mmm-dd-yyyy") & " Participant Report"
- Worksheets(1).Name = SheetName
- Sheets.Add After:=ActiveSheet
- Sheets("Sheet1").Select
- Sheets("Sheet1").Name = "Segmented Results"
- ActiveCell.FormulaR1C1 = "Segmented Results"
- Range("A1:C1").Select
- Application.WindowState = xlNormal
- With Selection.Font
- .Name = "Calibri"
- .Size = 20
- .Strikethrough = False
- .Superscript = False
- .Subscript = False
- .OutlineFont = False
- .Shadow = False
- .Underline = xlUnderlineStyleNone
- .ThemeColor = xlThemeColorLight1
- .TintAndShade = 0
- .ThemeFont = xlThemeFontMinor
- End With
- Selection.Font.Bold = True
- With Selection
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlBottom
- .WrapText = False
- .Orientation = 0
- .AddIndent = False
- .IndentLevel = 0
- .ShrinkToFit = False
- .ReadingOrder = xlContext
- .MergeCells = False
- End With
- Selection.Merge
- Range("A2").Select
- ActiveCell.FormulaR1C1 = "Group"
- Range("B2").Select
- ActiveCell.FormulaR1C1 = "# of Participants"
- Range("C2").Select
- ActiveCell.FormulaR1C1 = "$ Raised"
- Range("A3").Select
- ActiveCell.FormulaR1C1 = "$0 - $10"
- Range("A4").Select
- ActiveCell.FormulaR1C1 = "$10.01 - $50"
- Range("A5").Select
- ActiveCell.FormulaR1C1 = "$50.01 - $100"
- Range("A6").Select
- ActiveCell.FormulaR1C1 = "$100.01 - $200"
- Range("A7").Select
- ActiveCell.FormulaR1C1 = "$200.01 - $500"
- Range("A8").Select
- ActiveCell.FormulaR1C1 = "$500.01 - $1,000"
- Range("A9").Select
- ActiveCell.FormulaR1C1 = "$1,000.01 - $20,000"
- Columns("A:A").EntireColumn.AutoFit
- Range("A2:C2").Select
- Selection.Font.Bold = True
- With Selection.Font
- .Name = "Calibri"
- .Size = 13
- .Strikethrough = False
- .Superscript = False
- .Subscript = False
- .OutlineFont = False
- .Shadow = False
- .Underline = xlUnderlineStyleNone
- .ThemeColor = xlThemeColorLight1
- .TintAndShade = 0
- .ThemeFont = xlThemeFontMinor
- End With
- Columns("B:B").EntireColumn.AutoFit
- Columns("C:C").EntireColumn.AutoFit
- Range("C3:C9").Select
- Selection.Style = "Currency"
- Range("A2:C9").Select
- Selection.Borders(xlDiagonalDown).LineStyle = xlNone
- Selection.Borders(xlDiagonalUp).LineStyle = xlNone
- With Selection.Borders(xlEdgeLeft)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
- With Selection.Borders(xlEdgeTop)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
- With Selection.Borders(xlEdgeBottom)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
- With Selection.Borders(xlEdgeRight)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
- With Selection.Borders(xlInsideVertical)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
- With Selection.Borders(xlInsideHorizontal)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
- Selection.Borders(xlDiagonalDown).LineStyle = xlNone
- Selection.Borders(xlDiagonalUp).LineStyle = xlNone
- With Selection.Borders(xlEdgeLeft)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlMedium
- End With
- With Selection.Borders(xlEdgeTop)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlMedium
- End With
- With Selection.Borders(xlEdgeBottom)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlMedium
- End With
- With Selection.Borders(xlEdgeRight)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlMedium
- End With
- With Selection.Borders(xlInsideVertical)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
- With Selection.Borders(xlInsideHorizontal)
- .LineStyle = xlContinuous
- .ColorIndex = 0
- .TintAndShade = 0
- .Weight = xlThin
- End With
- Range("B3").Select
- Worksheets(1).Select
- Columns("A:B").Select
- Selection.Delete Shift:=xlToLeft
- Columns("B:C").Select
- Selection.Delete Shift:=xlToLeft
- Range("E1").Select
- ActiveCell.FormulaR1C1 = "Captain"
- Range("A1").Select
- ActiveCell.FormulaR1C1 = "Reg. Date"
- Range("A2").Select
- Columns("A:A").EntireColumn.AutoFit
- Columns("O:O").Select
- Selection.Delete Shift:=xlToLeft
- Columns("P:U").Select
- Selection.Delete Shift:=xlToLeft
- Range("P1").Select
- ActiveCell.FormulaR1C1 = "Survivor"
- Range("Q1").Select
- ActiveCell.FormulaR1C1 = "Caregiver"
- Columns("R:R").Select
- Selection.Delete Shift:=xlToLeft
- Selection.Delete Shift:=xlToLeft
- Range("R1").Select
- ActiveCell.FormulaR1C1 = "T-Shirt"
- Columns("S:S").Select
- Selection.Delete Shift:=xlToLeft
- Range("S1").Select
- ActiveCell.FormulaR1C1 = "Emails"
- Columns("T:U").Select
- Selection.Delete Shift:=xlToLeft
- Range("T1").Select
- ActiveCell.FormulaR1C1 = "Goal"
- Range("U1").Select
- ActiveCell.FormulaR1C1 = "$ given at registration"
- Range("V1").Select
- ActiveCell.FormulaR1C1 = "Returning?"
- Range("W1").Select
- Columns("W:X").Select
- Selection.Delete Shift:=xlToLeft
- Range("U9").Select
- Columns("B:C").Select
- Selection.Delete Shift:=xlToLeft
- Columns("A:A").Select
- Selection.Cut
- Columns("F:F").Select
- Selection.Insert Shift:=xlToRight
- Columns("B:B").Select
- Selection.Cut
- Columns("F:F").Select
- Selection.Insert Shift:=xlToRight
- Columns("F:F").Select
- Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
- Range("F1").Select
- ActiveCell.FormulaR1C1 = "$ Raised (Include Reg.)"
- Range("F2").Select
- ActiveCell.FormulaR1C1 = "=SUM(RC[3]:RC[5])"
- Range("F2").Select
- Selection.AutoFill Destination:=Range("F2", Range("F" & number))
- Range("F1", Range("F" & number)).Select
- Columns("F:F").Select
- Selection.Copy
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- Range("G3").Select
- Application.CutCopyMode = False
- Columns("G:K").Select
- Selection.Delete Shift:=xlToLeft
- Range("G1").Select
- ActiveCell.FormulaR1C1 = "Promo"
- Range("G2").Select
- Columns("N:N").Select
- Selection.Cut
- Columns("G:G").Select
- Selection.Insert Shift:=xlToRight
- Columns("N:N").Select
- Selection.Cut
- Columns("H:H").Select
- Selection.Insert Shift:=xlToRight
- Columns("K:K").Select
- Selection.Cut
- Columns("I:I").Select
- Selection.Insert Shift:=xlToRight
- Columns("K:K").EntireColumn.AutoFit
- Range("P3").Select
- Columns("A:A").ColumnWidth = 25.57
- Columns("B:B").ColumnWidth = 11.29
- Columns("C:C").ColumnWidth = 14.29
- Columns("E:E").EntireColumn.AutoFit
- Columns("F:F").EntireColumn.AutoFit
- Columns("G:G").EntireColumn.AutoFit
- Columns("H:H").EntireColumn.AutoFit
- Columns("I:I").EntireColumn.AutoFit
- Columns("I:I").ColumnWidth = 23.57
- Columns("J:J").EntireColumn.AutoFit
- Columns("P:P").Select
- Selection.Cut
- Columns("J:J").Select
- Selection.Insert Shift:=xlToRight
- Range("M2").Select
- Columns("A:P").Select
- Selection.AutoFilter
- Range("F2").Select
- Columns("F:F").EntireColumn.AutoFit
- ActiveWorkbook.Worksheets(1).AutoFilter.Sort.SortFields. _
- Add Key:=Range("F1", Range("F" & number)), SortOn:=xlSortOnValues, Order:=xlDescending, _
- DataOption:=xlSortTextAsNumbers
- With ActiveWorkbook.Worksheets(1).AutoFilter.Sort
- .Header = xlYes
- .MatchCase = False
- .Orientation = xlTopToBottom
- .SortMethod = xlPinYin
- .Apply
- End With
- Columns("F:F").Select
- Selection.FormatConditions.AddColorScale ColorScaleType:=3
- Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
- Selection.FormatConditions(1).ColorScaleCriteria(1).Type = _
- xlConditionValueLowestValue
- With Selection.FormatConditions(1).ColorScaleCriteria(1).FormatColor
- .Color = 7039480
- .TintAndShade = 0
- End With
- Selection.FormatConditions(1).ColorScaleCriteria(2).Type = _
- xlConditionValuePercentile
- Selection.FormatConditions(1).ColorScaleCriteria(2).Value = 50
- With Selection.FormatConditions(1).ColorScaleCriteria(2).FormatColor
- .Color = 8711167
- .TintAndShade = 0
- End With
- Selection.FormatConditions(1).ColorScaleCriteria(3).Type = _
- xlConditionValueHighestValue
- With Selection.FormatConditions(1).ColorScaleCriteria(3).FormatColor
- .Color = 8109667
- .TintAndShade = 0
- End With
- Range("G3").Select
- ActiveSheet.Range("$A$1", Range("P" & number)).AutoFilter Field:=6, Criteria1:="<=10", _
- Operator:=xlAnd
- Range("Q1").Select
- ActiveCell.FormulaR1C1 = "=SUBTOTAL(2,C[-11])"
- Range("R1").Select
- ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,C[-12])"
- Range("Q1:R1").Select
- Selection.Copy
- Sheets("Segmented Results").Select
- Range("B3:C3").Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- Columns("C:C").ColumnWidth = 12
- Range("B4").Select
- Worksheets(1).Select
- ActiveSheet.Range("$A$1", Range("P" & number)).AutoFilter Field:=6
- ActiveSheet.Range("$A$1", Range("P" & number)).AutoFilter Field:=6, Criteria1:=">=10.01" _
- , Operator:=xlAnd, Criteria2:="<=50"
- Application.CutCopyMode = False
- Selection.Copy
- Sheets("Segmented Results").Select
- Range("B4:C4").Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- Range("B5:C5").Select
- Worksheets(1).Activate
- Worksheets(1).Select
- ActiveSheet.Range("$A$1", Range("P" & number)).AutoFilter Field:=6
- ActiveSheet.Range("$A$1", Range("P" & number)).AutoFilter Field:=6, Criteria1:=">=50.01" _
- , Operator:=xlAnd, Criteria2:="<=100"
- Application.CutCopyMode = False
- Selection.Copy
- Sheets("Segmented Results").Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- Worksheets(1).Select
- ActiveSheet.Range("$A$1", Range("P" & number)).AutoFilter Field:=6, Criteria1:= _
- ">=100.01", Operator:=xlAnd, Criteria2:="<=200"
- Application.CutCopyMode = False
- Selection.Copy
- Sheets("Segmented Results").Select
- Range("B6:C6").Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- Worksheets(1).Select
- ActiveSheet.Range("$A$1", Range("P" & number)).AutoFilter Field:=6, Criteria1:= _
- ">=200.01", Operator:=xlAnd, Criteria2:="<=500"
- Application.CutCopyMode = False
- Selection.Copy
- Sheets("Segmented Results").Select
- Range("B7:C7").Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- Worksheets(1).Select
- ActiveSheet.Range("$A$1", Range("P" & number)).AutoFilter Field:=6, Criteria1:= _
- ">=500.01", Operator:=xlAnd, Criteria2:="<=1000"
- Application.CutCopyMode = False
- Selection.Copy
- Sheets("Segmented Results").Select
- Range("B8:C8").Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- Worksheets(1).Select
- ActiveSheet.Range("$A$1", Range("P" & number)).AutoFilter Field:=6, Criteria1:= _
- ">=1000.01", Operator:=xlAnd, Criteria2:="<=20000"
- Application.CutCopyMode = False
- Selection.Copy
- Sheets("Segmented Results").Select
- Range("B9:C9").Select
- Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
- :=False, Transpose:=False
- Worksheets(1).Activate
- ActiveSheet.Range("$A$1", Range("P" & number)).AutoFilter Field:=6
- Application.CutCopyMode = False
- Selection.ClearContents
- ActiveWindow.SmallScroll ToRight:=-4
- Range("A1").Select
- Sheets("Segmented Results").Activate
- Range("B10").Select
- ActiveCell.FormulaR1C1 = "=SUM(R[-7]C:R[-1]C)"
- Selection.AutoFill Destination:=Range("B10:C10"), Type:=xlFillDefault
- Range("C10").Select
- Selection.Style = "Currency"
- Range("B3:B10").Select
- Selection.NumberFormat = "#,##0"
- Range("B10:C10").Select
- Selection.Font.Bold = True
- Range("A12").Select
- ActiveCell.FormulaR1C1 = "% Non-Fundraisers:"
- Range("A13").Select
- ActiveCell.FormulaR1C1 = "Survivors:"
- Range("A14").Select
- ActiveCell.FormulaR1C1 = "Caregivers:"
- Range("B12").Select
- ActiveCell.FormulaR1C1 = "=R[-9]C/R[-2]C"
- Range("B12").Select
- Selection.Style = "Percent"
- Range("B13").Select
- ActiveCell.FormulaR1C1 = "=COUNTA('" & SheetName & "'!C[11]) - 1"
- Range("B14").Select
- ActiveCell.FormulaR1C1 = "=COUNTA('" & SheetName & "'!C[12]) - 1"
- Range("B12").Select
- Range("A15").Select
- ActiveCell.FormulaR1C1 = "Teams:"
- Range("B15").Select
- ActiveCell.FormulaR1C1 = "=COUNTUNIQUE('" & SheetName & "'!C[-1]) -2"
- Range("A1").Select
- Application.ScreenUpdating = True
- ActiveWorkbook.SaveAs Filename:="C:\Users\" & Environ$("Username") & "\Desktop\Dropbox\Relay 2016\Report Archive\" & SheetName, _
- FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
- ActiveWindow.WindowState = xlMaximized
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement