Option button selection disaapear.

edlim85

Board Regular
Joined
May 4, 2009
Messages
178
hi gurus,

I have this option button selection disappearing issue here. I hope to get some help here. I'll try my best to explain.

I have a macro that copy and rename a worksheet template (hidden) everytime the user click on a "+" button. the template contains option buttons for user to make select. the option buttions is named "OptionButton1".... "OptionButton4"..

I also notice this issue only happens when there are more than 1 copied template. I suspect is the way i code the macro. but then again I already declare the worksheet the macro should be working on.


Code:
For Each obj In ws.OLEObjects
        If TypeName(obj.Object) = "OptionButton" Then
            If obj.Name <> "OptionButton3" Then
                ws.OLEObjects(obj.Name).Object = False
            End If
        End If
    Next obj


I'm stuck and unsure where is wrong.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Thanks Andrew for your reply

the selection made by user on the option buttons was automatically clear.

i use the follow code to duplicate the template and subsequently rename it
Code:
Worksheets("EventTemplate").Copy after:=ws
Worksheets("EventTemplate (2)").Name = wsName
 
Upvote 0
What version of Excel are you using and how are you assigning the copied sheet to the ws variable? If OptionButton3 is checked it won't be unchecked. Is that what you want?
 
Upvote 0
Hi Andrew,

The copied sheets are named uniquely. i use activesheet as ws so that the codes only run on activesheet.

im using excel 2010. is it possible to send you the file im working on so what i say is clearer?
 
Upvote 0
hi Andrew,

I figure that i didnt group my option buttons that could be causing the problem.

is it possible to apply the loop below to a specific option button group?

Code:
For Each obj In ws.OLEObjects
        If TypeName(obj.Object) = "OptionButton" Then
            If obj.Name <> "OptionButton3" Then
                ws.OLEObjects(obj.Name).Object = False
            End If
        End If
    Next obj
 
Upvote 0
Thanks Andrew,

I found the solution. the problem surface becos i didnt group my option buttons.

Code:
    For Each obj In ws.OLEObjects
        If TypeName(obj.Object) = "OptionButton" Then
            If obj.Object.GroupName = ws.Name Then
                If obj.Name <> "OptionButton1" Then
                    ws.OLEObjects(obj.Name).Object = False
                End If
            End If
        End If
    Next obj
 
Upvote 0

Forum statistics

Threads
1,203,464
Messages
6,055,573
Members
444,799
Latest member
CraigCrowhurst

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