Option buttons formatting with VBA.

Radoslaw Poprawski

Active Member
Joined
Jun 19, 2021
Messages
398
Office Version
  1. 365
Platform
  1. Windows
so I have a question.

Im trying to cycle thru Option buttons, like in the code below,
However for some reason the counting method does not register the checkboxes.

What im doing wrong?
VBA Code:
Sub CheckBoxFormat()
Dim CHBX As Shape
Dim ActSht As Worksheet
Dim oOptButton As OptionButton
Dim i As Integer
Dim iButtonCount As Integer

Set ActSht = Sheet2


For iButtonCount = 1 To ActSht.OptionButtons.Count
        
        Set oOptButton = ActSht.OptionButtons(iButtonCount)
            Debug.Print oOptButton.Name

Next iButtonCount

End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Based on your complaint I'd guess that the loop is set as 1 To 0. If you don't know how to step through code and validate values, it is knowledge that you must have if you're going to use code. Google that subject in that case.
Try putting a message box before the loop: msgbox ActSht.OptionButtons.Count and see if you get zero (0) as the message. That would suggest your option buttons are shapes, not option button controls.
 
Upvote 0

Forum statistics

Threads
1,216,119
Messages
6,128,947
Members
449,480
Latest member
yesitisasport

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