Vba for Getting the control type....Please help!

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
Hi, i have seen this kinda code in the past however i cant locate it anymore...

If userform control.type = "Optionsbutton" then
rename it with some thing...
looping through all controls..


Thanks for helping!
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Dave, perfect thanks alot...

I have done small modification to the code....


this leads to one more question....



Code:
[/FONT]
[FONT=Courier New]Option Explicit
Sub renamecaptions()
Dim i As Long
Dim cCont As Control
i = 1
For Each cCont In Me.Controls
        If TypeName(cCont) = "OptionButton" Then
          cCont.Caption = Sheets("Sheet4").Range("A" & i).Text
        End If
        i = i + 1
Next cCont
End Sub[/FONT]
[FONT=Courier New][/FONT] 
[FONT=Courier New][/FONT] 
[FONT=Courier New]Is there anything as activecontrol.caption..[/FONT]
[FONT=Courier New]Instead writing different line of code for all the optionbuttons?[/FONT]
 
[FONT=Courier New]Private Sub OptionButton1_Click()
Range("A1").Value = Me.OptionButton1.Caption
End Sub[/FONT]
[FONT=Courier New]Private Sub OptionButton2_Click()
Range("A1").Value = Me.OptionButton2.Caption
End Sub[/FONT]
[FONT=Courier New]Private Sub OptionButton3_Click()
Range("A1").Value = Me.OptionButton3.Caption
End Sub[/FONT]
[FONT=Courier New]Private Sub OptionButton4_Click()
Range("A1").Value = Me.OptionButton4.Caption
End Sub
 
Upvote 0
Thanks again for the link Brian and Dave!!!
got it working....

Thanks again
Kind Regards
Pedie;)

Code:
[/FONT]
[FONT=Courier New]Sub loopandCheckvalues()
Dim cCont As Control
For Each cCont In Me.Controls
If TypeName(cCont) = "OptionButton" Then
 If cCont.Value = True Then
  Sheets("Sheet4").Range("B1").Value = cCont.Caption
 End If
End If
Next cCont
End Sub[/FONT]
[FONT=Courier New]Private Sub CommandButton1_Click()
 loopandCheckvalues
End Sub
Private Sub OptionButton1_Click()
loopandCheckvalues
End Sub
Private Sub OptionButton2_Click()
loopandCheckvalues
End Sub
Private Sub OptionButton3_Click()
loopandCheckvalues
End Sub
Private Sub OptionButton4_Click()
loopandCheckvalues
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,506
Messages
6,179,158
Members
452,892
Latest member
yadavagiri

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