Sub SetupCalc()
Const MyPassword As String = "dcccdc"
Dim ChangeProtection As Boolean
Dim z As Integer
Dim tbl As ListObject
Dim tblRow As ListRow
Set tbl = ThisWorkbook.Worksheets("Calc").ListObjects("Results")
' Removes the Protection
With Sheets("Calc")
If .ProtectContents = True Then
.Unprotect (MyPassword)
ChangeProtection = True
End If
' Check that the Bidders and Items tables are created in sheet Prep
If WorksheetFunction.CountA(ThisWorkbook.Worksheets("Prep").Range("G1")) = 0 Then
MsgBox "Please setup your bidders first"
Exit Sub
End If
If WorksheetFunction.CountA(ThisWorkbook.Worksheets("Prep").Range("G3")) = 0 Then
MsgBox "Please setup your items first"
Exit Sub
End If
' Copies the names of the Bidders from the Bidders Table in sheet Prep
ThisWorkbook.Worksheets("Calc").Range("F2").Value = ThisWorkbook.Worksheets("Prep").Range("B9").Value
ThisWorkbook.Worksheets("Calc").Range("H2").Value = ThisWorkbook.Worksheets("Prep").Range("B10").Value
ThisWorkbook.Worksheets("Calc").Range("J2").Value = ThisWorkbook.Worksheets("Prep").Range("B11").Value
ThisWorkbook.Worksheets("Calc").Range("L2").Value = ThisWorkbook.Worksheets("Prep").Range("B12").Value
ThisWorkbook.Worksheets("Calc").Range("N2").Value = ThisWorkbook.Worksheets("Prep").Range("B13").Value
ThisWorkbook.Worksheets("Calc").Range("P2").Value = ThisWorkbook.Worksheets("Prep").Range("B14").Value
ThisWorkbook.Worksheets("Calc").Range("R2").Value = ThisWorkbook.Worksheets("Prep").Range("B15").Value
ThisWorkbook.Worksheets("Calc").Range("T2").Value = ThisWorkbook.Worksheets("Prep").Range("B16").Value
ThisWorkbook.Worksheets("Calc").Range("V2").Value = ThisWorkbook.Worksheets("Prep").Range("B17").Value
ThisWorkbook.Worksheets("Calc").Range("X2").Value = ThisWorkbook.Worksheets("Prep").Range("B18").Value
z = ThisWorkbook.Worksheets("Prep").Range("G4").Value
' Add the required number of rows to the Results table in sheet Calc
Do Until z = 0
Set tblRow = tbl.ListRows.Add
tblRow.Range.Offset(-1).Copy
tblRow.Range.PasteSpecial xlPasteFormulasAndNumberFormats
z = z - 1
Loop
' Hides the columns that are not required
Dim C1 As Range
For Each C1 In ThisWorkbook.Worksheets("Calc").Range("F1:Y1")
C1.EntireColumn.Hidden = C1.Value = "0"
Next C1
' Copies the formulas for SMALL and LARGE
' Range("D4:D8").FormulaR1C1 = "=IFERROR(AGGREGATE(15,6,RC6:RC24/(RC6:RC24<>"""")/(R7C7:R7C25=""COMPLIANT""),1),""No Data"")"
' Range("E4:E8").FormulaR1C1 = "=IFERROR(AGGREGATE(14,6,RC6:RC24/(RC6:RC24<>"""")/(R7C7:R7C25=""COMPLIANT""),1),""No Data"")"
' Protects the sheet
If ChangeProtection = True Then .Protect (MyPassword)
End With
Application.CutCopyMode = False
Worksheets("Calc").Activate
Range("F4").Select
End Sub