ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Clearing Option Buttons (https://www.excelbanter.com/excel-programming/318219-clearing-option-buttons.html)

dsimcox

Clearing Option Buttons
 
I have a set of 80 Option Buttons (from Control Toolbox) in a questionaire.
I want to clear all of them after a macro posts the results to another sheet.
I can clear them individually with this line in my code like this (for
Option Button 79):

ActiveSheet.OptionButton79.Object.Value = False

For some reason, if I generalize this by trying to clear them with a loop,
it fails.
Here is the code I have tried unsuccessfully to use:

Sub ClearOptBut()
Dim i As Integer
For i = 1 To 80
ActiveSheet.OptionButton(i).Object.Value = False
Next i
End Sub

It hangs up on

ActiveSheet.OptionButton(i).Object.Value = False


Frank Kabel

Clearing Option Buttons
 
Hi
try (not tested):
Sub ClearOptBut()
Dim i As Integer
For i = 1 To 80
with ActiveSheet.controls("OptionButton" & i)
.Value = False
end with
Next i
End Sub


--
Regards
Frank Kabel
Frankfurt, Germany

"dsimcox" schrieb im Newsbeitrag
...
I have a set of 80 Option Buttons (from Control Toolbox) in a

questionaire.
I want to clear all of them after a macro posts the results to

another sheet.
I can clear them individually with this line in my code like this

(for
Option Button 79):

ActiveSheet.OptionButton79.Object.Value = False

For some reason, if I generalize this by trying to clear them with a

loop,
it fails.
Here is the code I have tried unsuccessfully to use:

Sub ClearOptBut()
Dim i As Integer
For i = 1 To 80
ActiveSheet.OptionButton(i).Object.Value = False
Next i
End Sub

It hangs up on

ActiveSheet.OptionButton(i).Object.Value = False




All times are GMT +1. The time now is 09:41 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com