Advertisement
murp

Add multiple checkboxes in Excel

Jan 31st, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.97 KB | None | 0 0
  1. ' This code will allow you to add multiple check boxes in Excel
  2. Sub AddCheckBoxes()
  3.     On Error Resume Next
  4.     Dim c As Range, myRange As Range
  5.     Set myRange = Selection
  6.     For Each c In myRange.Cells
  7.         ActiveSheet.CheckBoxes.Add(c.Left, c.Top, c.Width, c.Height).Select
  8.             With Selection
  9.                 .LinkedCell = c.Address
  10.                 .Characters.Text = ""
  11.                 .Name = c.Address
  12.             End With
  13.             c.Select
  14.             With Selection
  15.                 .FormatConditions.Delete
  16.                 .FormatConditions.Add Type:=xlExpression, _
  17.                     Formula1:="=" & c.Address & "=TRUE"
  18.                 .FormatConditions(1).Font.ColorIndex = 6 'change for other color when ticked
  19.                 .FormatConditions(1).Interior.ColorIndex = 6 'change for other color when ticked
  20.                 .Font.ColorIndex = 2 'cell background color = White
  21.             End With
  22.         Next
  23.         myRange.Select
  24. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement