Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have 12 optionbuttons and I am trying to run this code:
objOB1...objOB12 Private objOB As Object .... Set objOB = OptionButton For n = 1 To 12 If objOB(n).Value = True Then Month = n Next n but it gives me a Run-time error '91' What I am doing wrong? |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
If you have named your OptionButtons objOB1, objOB2, etc then you can use
For n = 1 To 12 If objOB & n = True Then month = n Next "Joao" wrote: I have 12 optionbuttons and I am trying to run this code: objOB1...objOB12 Private objOB As Object ... Set objOB = OptionButton For n = 1 To 12 If objOB(n).Value = True Then Month = n Next n but it gives me a Run-time error '91' What I am doing wrong? |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Jesus! Sometimes I'm really so dumb... Thank you very much JLGWhiz, sometimes
we'd get ourselves in such intricated problem, yet the solution is simple easy... "JLGWhiz" wrote: If you have named your OptionButtons objOB1, objOB2, etc then you can use For n = 1 To 12 If objOB & n = True Then month = n Next "Joao" wrote: I have 12 optionbuttons and I am trying to run this code: objOB1...objOB12 Private objOB As Object ... Set objOB = OptionButton For n = 1 To 12 If objOB(n).Value = True Then Month = n Next n but it gives me a Run-time error '91' What I am doing wrong? |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sorry, at a first look I thought it could work out but then again nothing. It
doesn't work, JLGWhiz. "Joao" wrote: Jesus! Sometimes I'm really so dumb... Thank you very much JLGWhiz, sometimes we'd get ourselves in such intricated problem, yet the solution is simple easy... "JLGWhiz" wrote: If you have named your OptionButtons objOB1, objOB2, etc then you can use For n = 1 To 12 If objOB & n = True Then month = n Next "Joao" wrote: I have 12 optionbuttons and I am trying to run this code: objOB1...objOB12 Private objOB As Object ... Set objOB = OptionButton For n = 1 To 12 If objOB(n).Value = True Then Month = n Next n but it gives me a Run-time error '91' What I am doing wrong? |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
What kind of optionbuttons are they?
Are they on a worksheet from the Forms toolbar? Are they on a worksheet from the Control toolbox toolbar? Are they on a Userform (designed inside the VBE)? If they're on a worksheet from the Forms toolbar: Dim OptBtn as optionbutton dim n as long Dim myMonth as long mymonth = 0 for n = 1 to 12 if worksheets("sheet9999").optionbuttons(n) = true then mymonth = n exit for end if next n if mymonth = 0 then msgbox "no optionbutton selected" else msgbox mymonth end if ========== if they're on a worksheet from the control toolbox toolbar and you named them nicely (Optionbutton1 through Optionbutton12), you could use: dim OLEObj as OLEObject dim n as long Dim myMonth as long mymonth = 0 for n = 1 to 12 if worksheets("sheet9999").oleobjects("Optionbutton" & n).object.value _ = true then mymonth = n exit for end if next n if mymonth = 0 then msgbox "no optionbutton selected" else msgbox mymonth end if ========== if they're on a userform you named them nicely (Optionbutton1 through Optionbutton12), you could use: Dim Ctrl As Control Dim n As Long Dim myMonth As Long myMonth = 0 For n = 1 To 12 If Me.Controls("Optionbutton" & n).Value = True Then myMonth = n Exit For End If Next n If myMonth = 0 Then MsgBox "no optionbutton selected" Else MsgBox myMonth End If Joao wrote: I have 12 optionbuttons and I am trying to run this code: objOB1...objOB12 Private objOB As Object ... Set objOB = OptionButton For n = 1 To 12 If objOB(n).Value = True Then Month = n Next n but it gives me a Run-time error '91' What I am doing wrong? -- Dave Peterson |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thank you very much Dave! I just needed one line of code of your help.
Private OLEObj As OLEObject 'OLE para OptionButton (Botões de Opção) Function DescMeses(intIndice As Byte) DescMeses = Choose(intIndice, "Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", _ "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro") End Function Private Sub BotaoOpcoes() byteMes = Month(Date) For k = 1 To 12 If OLEObjects("objOB" & k).Object.Value = True Then Mes = k Next k DescMes = DescMeses(Mes) End Sub "Dave Peterson" wrote: What kind of optionbuttons are they? Are they on a worksheet from the Forms toolbar? Are they on a worksheet from the Control toolbox toolbar? Are they on a Userform (designed inside the VBE)? If they're on a worksheet from the Forms toolbar: Dim OptBtn as optionbutton dim n as long Dim myMonth as long mymonth = 0 for n = 1 to 12 if worksheets("sheet9999").optionbuttons(n) = true then mymonth = n exit for end if next n if mymonth = 0 then msgbox "no optionbutton selected" else msgbox mymonth end if ========== if they're on a worksheet from the control toolbox toolbar and you named them nicely (Optionbutton1 through Optionbutton12), you could use: dim OLEObj as OLEObject dim n as long Dim myMonth as long mymonth = 0 for n = 1 to 12 if worksheets("sheet9999").oleobjects("Optionbutton" & n).object.value _ = true then mymonth = n exit for end if next n if mymonth = 0 then msgbox "no optionbutton selected" else msgbox mymonth end if ========== if they're on a userform you named them nicely (Optionbutton1 through Optionbutton12), you could use: Dim Ctrl As Control Dim n As Long Dim myMonth As Long myMonth = 0 For n = 1 To 12 If Me.Controls("Optionbutton" & n).Value = True Then myMonth = n Exit For End If Next n If myMonth = 0 Then MsgBox "no optionbutton selected" Else MsgBox myMonth End If Joao wrote: I have 12 optionbuttons and I am trying to run this code: objOB1...objOB12 Private objOB As Object ... Set objOB = OptionButton For n = 1 To 12 If objOB(n).Value = True Then Month = n Next n but it gives me a Run-time error '91' What I am doing wrong? -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Insert Object Problem | Excel Discussion (Misc queries) | |||
insert object problem | Excel Discussion (Misc queries) | |||
Problem using an object inside another object.. | Excel Programming | |||
Object Is Object evaluation problem | Excel Programming | |||
Problem with ADO with Parameter Object | Excel Programming |