Consulting

Results 1 to 6 of 6

Thread: Extracting groups of Options button

  1. #1
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location

    Extracting groups of Options button

    I am looking for ideas as to how best to extract the state of groups of Options button. I will be creating 30 groups of options button with 3 in each group on a sheet. What is the best way to get the state of each group? I have this preliminary sheet that I started. Hopefully, there is an easy way. Thanks.
    Attached Files Attached Files

  2. #2
    Maybe
    Sub CollectOptionButtonValues()
        Dim OpGroups As Collection
        Dim Sh As Shape, Ws As Worksheet, o As Object
        Dim GroupName As String, GroupValue As String
        
        
        Set Ws = ActiveSheet
        Set OpGroups = New Collection
        For Each Sh In Ws.Shapes
            Set o = Nothing
            On Error Resume Next
            Set o = Sh.OLEFormat.Object.Object
            On Error GoTo 0
            If Not o Is Nothing Then
                If LCase(TypeName(o)) = "optionbutton" Then
                    If o.Value = True Then
                        GroupName = o.GroupName
                        Select Case Sh.TopLeftCell.Column
                        Case 4
                            GroupValue = "Satisfactory"
                        Case 5
                            GroupValue = "Requires Action"
                        Case 6
                            GroupValue = "Not Applicable"
                        End Select
                        OpGroups.Add GroupValue, GroupName
                    End If
                End If
            End If
        Next
        
        Debug.Print OpGroups("ERP")
        Debug.Print OpGroups("Signage1")
        Debug.Print OpGroups("Signage2")
        Debug.Print OpGroups("Signage3")
    End Sub
    -------------------------------------------------
    The more details you give, the easier it is to understand your question. Don't save the effort, tell us twice rather than not at all. The amount of info you give strongly influences the quality of answer, and also how fast you get it.

  3. #3
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    Thanks Jimmy, this really helps! One question, with the collection, I was trying to get the KEY, so I can get the group name (without what you did at the bottom by entering it). The way I am doing it without the key is that I also put the GroupName into the GroupValue.

  4. #4
    It all depends on how you want to use the values. I thought the group names are fixed, and each one of them is used for a unique, specific purpose.
    But anyway, if you want to have the group names at hand, I would collect them in an array:

    Sub CollectOptionButtonValues()
        Dim OpGroups As Collection
        Dim Sh As Shape, Ws As Worksheet, o As Object
        Dim GroupName As String, GroupValue As String
        Dim GroupNames As String, arrGN
        Dim i As Long
        
        Set Ws = ActiveSheet
        Set OpGroups = New Collection
        For Each Sh In Ws.Shapes
            Set o = Nothing
            On Error Resume Next
            Set o = Sh.OLEFormat.Object.Object
            On Error GoTo 0
            If Not o Is Nothing Then
                If LCase(TypeName(o)) = "optionbutton" Then
                    If o.Value = True Then
                        GroupName = o.GroupName
                        Select Case Sh.TopLeftCell.Column
                        Case 4
                            GroupValue = "Satisfactory"
                        Case 5
                            GroupValue = "Requires Action"
                        Case 6
                            GroupValue = "Not Applicable"
                        End Select
                        OpGroups.Add GroupValue, GroupName
                        GroupNames = GroupNames & "," & GroupName
                    End If
                End If
            End If
        Next
        GroupNames = Mid(GroupNames, 2)
        arrGN = Split(GroupNames, ",")
        
        For i = LBound(arrGN) To UBound(arrGN)
            Debug.Print arrGN(i) & " - " & OpGroups(arrGN(i))
        Next
    End Sub
    -------------------------------------------------
    The more details you give, the easier it is to understand your question. Don't save the effort, tell us twice rather than not at all. The amount of info you give strongly influences the quality of answer, and also how fast you get it.

  5. #5
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    Thanks again, Jimmy.
    Yes, the group names are fixed. I just did not want to type all of them in. I did something similar to what you did by concatenating the Group Name into the GroupValue. I thought that I could access the KEY directly, I just was not able to, so I asked that question.

  6. #6
    You're welcome. Sorry if I didn't understand your question (because there was no question mark ), but anyway I 'm glad you found the solution
    -------------------------------------------------
    The more details you give, the easier it is to understand your question. Don't save the effort, tell us twice rather than not at all. The amount of info you give strongly influences the quality of answer, and also how fast you get it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •