Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Object problem

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Object problem

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Object problem

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Object problem

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Object problem

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Object problem

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Object Problem Raj Excel Discussion (Misc queries) 1 April 20th 10 05:18 PM
insert object problem Jeremy Excel Discussion (Misc queries) 0 October 2nd 07 09:34 PM
Problem using an object inside another object.. Michel S. Excel Programming 2 March 1st 07 09:59 PM
Object Is Object evaluation problem mickey Excel Programming 4 November 20th 06 05:40 PM
Problem with ADO with Parameter Object Tod Excel Programming 1 May 7th 04 11:03 AM


All times are GMT +1. The time now is 04:53 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"