Hello,
I have the following code that I picked up from some web page. This one inserts only one button to the left of the cell.
I would like to have two checkboxes in one cell, one for "Yes" another for "No" and only one can be checked.
I tried to replicate second option by adding "1" to the variable. Why "Middle" or "Right" doesn't work?
Thanks.
Here is the whole code:
I have the following code that I picked up from some web page. This one inserts only one button to the left of the cell.
I would like to have two checkboxes in one cell, one for "Yes" another for "No" and only one can be checked.
I tried to replicate second option by adding "1" to the variable. Why "Middle" or "Right" doesn't work?
Thanks.
Code:
Set myCBX1 = wks.CheckBoxes.Add _
(Top:=.Top, Width:=.Width, _
Height:=.Height, Middle:=.Middle)
Here is the whole code:
Code:
Sub AddCheckBoxesRange()
'by Dave Peterson
'add Form checkboxes
Dim c As Range
Dim myCBX As CheckBox
Dim myCBX1 As CheckBox
Dim wks As Worksheet
Dim rngCB As Range
Dim rngCB1 As Range
Dim strCap As String
Dim strCap1 As String
Set wks = ActiveSheet
Set rngCB = wks.Range("J23:J26")
Set rngCB1 = wks.Range("J23:J26")
'Set rngCB = Selection
strCap = "YES"
strCap1 = "NO"
For Each c In rngCB
With c
Set myCBX = wks.CheckBoxes.Add _
(Top:=.Top, Width:=.Width, _
Height:=.Height, Left:=.Left)
End With
With myCBX
.Name = "cbx_" & c.Address(0, 0)
.LinkedCell = c.Offset(23, 10) _
.Address(external:=True)
.Caption = strCap
' .OnAction = ThisWorkbook.Name _
' & "!mycbxMacro"
End With
Next c
For Each c In rngCB1
With c
Set myCBX1 = wks.CheckBoxes.Add _
(Top:=.Top, Width:=.Width, _
Height:=.Height, Middle:=.Middle)
End With
With myCBX1
.Name = "cbx1_" & c.Address(0, 0)
.LinkedCell = c.Offset(23, 10) _
.Address(external:=True)
.Caption = strCap1
' .OnAction = ThisWorkbook.Name _
' & "!mycbxMacro"
End With
Next c
End Sub