Thursday, May 25, 2023

Excel Mind - VBA Code To Add Multiple Checkbox In Multiple Cells Excel

 VBA Code To Add Multiple Checkbox In Multiple Cells Excel 



Sub CreateCheckboxesWithCellReferences()
    Dim ws As Worksheet
    Dim rng As Range
    Dim cb As CheckBox
    Dim cell As Range
    
    ' VBA Code By Excelmind
    ' Set the worksheet where you want to add checkboxes
    Set ws = ThisWorkbook.Sheets("Sheet1")
    
    ' Select the range where you want to add checkboxes
    Set rng = Application.InputBox("Select a range", Type:=8)
    
    ' Loop through each cell in the selected range
    For Each cell In rng
        ' Create a checkbox in each cell
        Set cb = ws.CheckBoxes.Add(cell.Left, cell.Top, cell.Width, cell.Height)
        
        ' Set the linked cell for the checkbox
        cb.LinkedCell = cell.Address
        
        ' Adjust the checkbox appearance
        cb.Caption = ""
        cb.Value = xlOff
    Next cell
End Sub

No comments:

Post a Comment

How To Use Vlookup In Merged Cells

  How To Use Vlookup In Merged Cells Click Here to download sample file for practice Note: Download the file and open with microsoft excel