![]() |
Iterate through a form
Hi. This is probably easy stuff, but I can't seem to do it! Here goes... I have a form that contains several OptionButtons. These are all hel in a frame on my UserForm. There are also Labels in the frame next t the OptionButton that identifies its purpose to the user. I would like to find a way of iterating through the frame to identif which OptionButton has been selected. Then, using the associate Caption of the OptionButton I would like to enter this value into cell on a worksheet. I've been having real trouble with this. I'm just trying to do project for work that will really make my life easier there, I'm not a Excel superuser! If anyone can help I'd be real grateful. Thanks, Rob -- RobEdgele ----------------------------------------------------------------------- RobEdgeler's Profile: http://www.excelforum.com/member.php...fo&userid=2733 View this thread: http://www.excelforum.com/showthread.php?threadid=46835 |
Iterate through a form
Is there a reason you didn't use the caption of the optionbutton as the
identifier? If I named the optionbuttons and labels nicely, this worked ok: Option Explicit Private Sub CommandButton1_Click() Unload Me End Sub Private Sub CommandButton2_Click() Dim myCtrl As Control Dim iCtr As Long Dim FoundIt As Boolean iCtr = 0 FoundIt = False For Each myCtrl In Me.Frame1.Controls If TypeOf myCtrl Is MSForms.OptionButton Then iCtr = iCtr + 1 If myCtrl.Value = True Then MsgBox myCtrl.Caption FoundIt = True Exit For End If End If Next myCtrl If FoundIt = True Then MsgBox Me.Frame1.Controls("Label" & iCtr).Caption Else MsgBox "Nothing selected" End If End Sub That "msgbox myctrl.caption" might be all you really need with a minor change to the form??? RobEdgeler wrote: Hi. This is probably easy stuff, but I can't seem to do it! Here goes... I have a form that contains several OptionButtons. These are all held in a frame on my UserForm. There are also Labels in the frame next to the OptionButton that identifies its purpose to the user. I would like to find a way of iterating through the frame to identify which OptionButton has been selected. Then, using the associated Caption of the OptionButton I would like to enter this value into a cell on a worksheet. I've been having real trouble with this. I'm just trying to do a project for work that will really make my life easier there, I'm not an Excel superuser! If anyone can help I'd be real grateful. Thanks, Rob. -- RobEdgeler ------------------------------------------------------------------------ RobEdgeler's Profile: http://www.excelforum.com/member.php...o&userid=27336 View this thread: http://www.excelforum.com/showthread...hreadid=468356 -- Dave Peterson |
Iterate through a form
Thank you very much for your help, I'm pleased to say that it work really good! Have a nice day. Rob. :) :) :) : -- RobEdgele ----------------------------------------------------------------------- RobEdgeler's Profile: http://www.excelforum.com/member.php...fo&userid=2733 View this thread: http://www.excelforum.com/showthread.php?threadid=46835 |
All times are GMT +1. The time now is 07:12 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com