Sub AddCheckboxes()
Dim cellValue As Integer
Dim i As Integer
Dim chkBox As Object
Dim startLeft As Double, startTop As Double
Dim targetRange As Range
Dim cell As Range
Sheets("Sheet1").Activate
cellValue = Range("I4").Value
If Not IsNumeric(cellValue) Or cellValue <= 0 Then
MsgBox "Please enter a valid number in cell I4", vbExclamation
Exit Sub
End If
startTop = 0
Set targetRange = Range("L4").Resize(1, cellValue)
For Each cell In targetRange
Set chkBox = ActiveSheet.CheckBoxes.Add(cell.Left, cell.Top, cell.Width,
cell.Height)
chkBox.Caption = ""
chkBox.Name = "CheckBox_" & cell.Address
chkBox.LinkedCell = cell.Offset(0, 4).Address
Next cell
End Sub
Sub InsertRow()
Dim rowNumber As Integer
rowNumber = 4
Rows(rowNumber).Insert Shift:=xlDown
End Sub
Sub CopyAndPasteVerticalToHorizontal()
Dim wsA As Worksheet
Dim wsB As Worksheet
Dim sourceRange As Range
Dim targetCell As Range
Dim i As Integer
Set wsA = ThisWorkbook.Sheets("Form")
Set wsB = ThisWorkbook.Sheets("Sheet1")
Set sourceRange = wsA.Range("F20:F24")
Set targetCell = wsB.Range("F4")
For i = 1 To sourceRange.Rows.Count
targetCell.Offset(0, i - 1).Value = sourceRange.Cells(i, 1).Value
Next i
End Sub
Sub EnterFormulaInCell()
Dim targetCell As Range
Set targetCell = Range("O4")
targetCell.Formula = "=IF($I4=0,"""",COUNTIF(P4:R4,""TRUE"")/$I4)"
targetCell.NumberFormat = "0%"
End Sub
Sub RunAllMacros()
CopyAndPasteVerticalToHorizontal
AddCheckboxes
EnterFormulaInCell
InsertRow
End Sub