Loop through OLE objects within a Group

AskMyDog

New Member
Joined
Nov 13, 2015
Messages
16
Hi all,

Anyone know how to loop through the OLE objects in a specified GroupName?

I have a macro that creates rows of option buttons to a row of a table, and I've assigned each option button a GroupName with the corresponding row number, and each button has the row and the number button it is, but I can't figure out how to loop through each option button in a specified group.

Anyone have any ideas?

Here's what I currently have:

Code:
Sub resort_reconciled_meds()

Dim i, j, delRow, TableTop, TableLeft, TableRows, DataRows As Long
Dim lotarget As ListObject
Dim Rec_Sht As Worksheet
Dim Opt_Btn as Object


Set Rec_Sht = Worksheets("Reconcile Meds Here")
Set lotarget = Rec_Sht.ListObjects("Table3")
TableTop = lotarget.Range.Row
TableLeft = lotarget.Range.Column
TableRows = lotarget.DataBodyRange.Rows.Count
Sort_Index = lotarget.ListColumns("Sort").Index
DataRows = lotarget.DataBodyRange.Rows.Count
Opt_Btn_Count = 4




For i = 1 To DataRows
For j = 1 To Opt_Btn_Count
Opt_Btn = Rec_Sht.OLEObjects.Name("RecBtn" & "_" & i & "_" & j)
If Opt_Btn.Value = True Then
lotarget.DataBodyRange(i, Sort_Index).Value = j
End If
Next j
Next i




For i = 1 To TableRows
If Cells(i + TableTop, TableLeft + Sort_Index) = 4 Then
lotarget.Range.Rows(i + 1).ClearContents
Rec_Sht.Cells(i + TableTop, "c") = i
End If
Next i


For j = 1 To TableRows
If IsEmpty(Cells(TableTop + j, TableLeft)) = False Then
DataRows = DataRows + 1
End If
Next j




lotarget.Resize lotarget.Range.Resize(DataRows + 1, lotarget.Range.Columns.Count)


End Sub
 

Some videos you may like

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
5,680
Office Version
2019
Platform
Windows
Hi,
see if following example code helps you.

Code:
   For i = 1 To 6
        MsgBox Sheets("Sheet1").OLEObjects("CheckBox" & i).Object.GroupName
        MsgBox Sheets("Sheet1").OLEObjects("CheckBox" & i).Object.Value
    Next
Code assumes that you have 6 CheckBoxes with their default names ("CheckBox1" etc) on worksheet Named "Sheet1"

You should be able to adapt in to your project.

Dave
 

Watch MrExcel Video

Forum statistics

Threads
1,095,394
Messages
5,444,218
Members
405,274
Latest member
go2nivas

This Week's Hot Topics

Top