Delete Active X Radio Buttons

Learn_VBA

New Member
Joined
Oct 9, 2017
Messages
25
I have a macro which copies over the relevant data from one tab to a new tab within a new workbook. However, it also copies across two radio buttons which I no longer need within the new document. How do I delete these?

The two radio buttons cover cells U3 to AB 20
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
When you say "Radio Buttons", I assume that you mean option buttons, correct? If so, the following examples assume that Sheet1 contains the option buttons to be deleted.

1) If the option buttons are the only ActiveX controls on the worksheet, and you want to delete all of them...

Code:
Worksheets("Sheet1").OLEObjects.Delete

2) If the option buttons are the only ActiveX controls on the worksheet, and you only want to delete the ones where the top left corner of the button lies over the range "U3:AB20"...

Code:
Dim OleObj As OLEObject

For Each OleObj In Worksheets("Sheet1").OLEObjects
    If Not Application.Intersect(Worksheets("Sheet1").Range("U3:AB20"), OleObj.TopLeftCell) Is Nothing Then
        OleObj.Delete
    End If
Next OleObj

3) If the worksheet contains other types of ActiveX controls, and you want to delete all option buttons...

Code:
Dim OleObj As OLEObject

For Each OleObj In Worksheets("Sheet1").OLEObjects
    If TypeName(OleObj.Object) = "OptionButton" Then
        OleObj.Delete
    End If
Next OleObj

4) If the worksheet contains other types of ActiveX controls, and you only want to delete the ones where the top left corner of the button lies over the range "U3:AB20"...

Code:
Dim OleObj As OLEObject

For Each OleObj In Worksheets("Sheet1").OLEObjects
    If TypeName(OleObj.Object) = "OptionButton" Then
        If Not Application.Intersect(Worksheets("Sheet1").Range("U3:AB20"), OleObj.TopLeftCell) Is Nothing Then
            OleObj.Delete
        End If
    End If
Next OleObj

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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