Selecting only group boxes, not the option buttons inside

deepfriedcheese

New Member
Joined
Aug 6, 2010
Messages
21
I have a spreadsheet originally created with Excel 2000 or earlier, but now running in Excel 2010 on a Windows 7 machine. One of the sheets in this workbook has several dozen group boxes created from the Form Controls menu. Inside each group box are exactly two option buttons also created from the Form Controls menu.

This spreadsheet has passed through many hands and is a mess to look at. The group boxes and option buttons are in two columns, but they are not even close to being in a straight line. Because I have several spreadsheets of this nature to maintain for a large group of users, I'd like them to look more presentable without going blind manually moving boxes and buttons around.

My question: Using a macro, is there a way to select only the group boxes in order to resize or move them? I assume if it can be done for the group boxes, the option buttons should work the same. I can loop through all of the shapes on the sheet and set height and position relative to the top of the cell without differentiating between the types of controls, but to set the width I need to know whether each shape is a group box or an option button as otherwise the option buttons would overlap and extend beyond the right edge of the group box.

This is the code I have so far to clean these spreadsheets up.

Code:
Sub DynamicRepair()
'Look through the selected range.  Set group boxes and radio buttons to preset positions.
Dim myshape As Shape
 
For Each cell In Selection
    For Each myshape In ActiveSheet.Shapes
            If Not Intersect(myshape.TopLeftCell, cell.EntireRow) Is Nothing Then
                'Set a fixed height
                myshape.Height = 0.75
                'Center vertically in cell
                myshape.Top = cell.Top + ((cell.Height / 2) - 9.75)
 
            End If
    Next
Next
 
End Sub

I realize I will probably need to remove the EntireRow criteria from the selection when I figure out how to set the width of the types individually.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
This code will sort out what kind of shape one is dealing with.

Code:
Dim oneShape As Shape

For Each oneShape In ActiveSheet.Shapes
    With oneShape
        If .Type = msoFormControl Then
            Select Case .FormControlType
                Case xlGroupBox
                    MsgBox .Name & " is a group box"
                Case xlOptionButton
                    MsgBox .Name & " is an option button"
            End Select
        Else
            MsgBox .Name & " is not a form control"
        End If
    End With
Next oneShape
 
Upvote 0

Forum statistics

Threads
1,214,823
Messages
6,121,777
Members
449,049
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top