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

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
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,223,893
Messages
6,175,239
Members
452,621
Latest member
Laura_PinksBTHFT

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