I can't for the life of me figure out how to group non-activeX option buttons. I want to be able to group all the buttons in the "for j to Opt_Btn_count" loop.
Does anyone have any idea how to do this?
Does anyone have any idea how to do this?
Code:
Sub Add_XOptionBtns()
Dim CLeft, CTop, CHeight, CWidth As Double
Dim lotarget As Excel.ListObject
Dim TableTop, i, TargetDataRowsCount As Long
Dim oCheck As OLEObject
Dim Rec_Sht As Worksheet
Dim Opt_Btn_Count As Long
Application.ScreenUpdating = False
Set Rec_Sht = Sheets("Reconcile Meds Here")
Set lotarget = Sheets("Reconcile Meds Here").ListObjects("Table3")
TableTop = lotarget.Range.Row
TableLeft = lotarget.Range.Column
Sort_Index = lotarget.ListColumns("Sort").Index
Opt_Btn_Count = 4
For Each OptBtn In Sheets("Reconcile Meds Here").OptionButtons
OptBtn.Delete
Next OptBtn
TargetDataRowsCount = lotarget.DataBodyRange.Rows.Count
For i = 1 To TargetDataRowsCount
If Not IsEmpty(Cells(TableTop + i, "c")) Then
' GrpBox_Cell = Cells(TableTop + i, "A")
' Set GrpBox = Rec_Sht.GroupBoxes.Add(Top:=GrpBox_Cell.Top, Left:=GrpBox_Cell.Left, Height:=GrpBox_Cell.Height, Width:=GrpBox_Cell.Width)
' GrpBox.Name = "GrpBox" & i
For j = 1 To Opt_Btn_Count
CLeft = Cells(TableTop + i, "A").Left + (Cells(TableTop + i, "A").Width * ((j / Opt_Btn_Count) - 0.25))
CTop = Cells(TableTop + i, "A").Top ' + Cells(TableTop + i, "A").Height * 0.25
CHeight = Cells(TableTop + i, "A").Height * 0.5
CWidth = Cells(TableTop + i, "A").Width / Opt_Btn_Count
With Rec_Sht.OptionButtons.Add(Top:=CTop, Left:=CLeft, Height:=CHeight, Width:=CWidth)
.Caption = ""
.Value = False
.Name = "RecBtn" & i & "_" & j
.LinkedCell = Cells(TableTop + i, TableLeft + Sort_Index)
OptBtnGrp(j) = .Name
End With
Next j
End If
Next i
Application.ScreenUpdating = True
End Sub