0% found this document useful (0 votes)
2 views

Sub AddCheckboxesBasedOnAdjacentCells

The document contains a series of VBA macros for Excel that automate tasks such as adding checkboxes based on a value in cell I4, inserting a row, copying and pasting data from one sheet to another, and entering a formula in cell O4. The macros are designed to run sequentially through the 'RunAllMacros' subroutine. Each macro is defined to perform specific actions on the specified worksheets and ranges.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Sub AddCheckboxesBasedOnAdjacentCells

The document contains a series of VBA macros for Excel that automate tasks such as adding checkboxes based on a value in cell I4, inserting a row, copying and pasting data from one sheet to another, and entering a formula in cell O4. The macros are designed to run sequentially through the 'RunAllMacros' subroutine. Each macro is defined to perform specific actions on the specified worksheets and ranges.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

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

You might also like