Clearing values of Different control type inside a frame with vba

mahhdy

Board Regular
Joined
Sep 15, 2016
Messages
86
Hi,
I have a user form which includes two frames one is header and the second is "body". Each has text box and combo box controls, I want to clear all the content of body controls, no matter of the control types. Also, I need to know if I add for instance radio button How I should change the code to that control type be cleared too.
Tnx.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Let's assume that your second or "body" frame is named Frame2, the following code will iterate through each control (textbox, combobox, and option button) within the frame and clear them...

Code:
Private Sub CommandButton2_Click()
    Dim oCtrl As Control
    For Each oCtrl In Me.Frame2.Controls
        Select Case TypeName(oCtrl)
            Case "TextBox", "ComboBox"
                oCtrl.Value = ""
            Case "OptionButton"
                oCtrl.Value = False
        End Select
    Next oCtrl
End Sub

Change the name of the frame, accordingly.

Hope this helps!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,858
Members
449,052
Latest member
Fuddy_Duddy

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