Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Problem looping through combobox

I have a chartsheet with a combobox. I want to loop through the combobox that
has 15 items. However the following macro gives an error "1004". It loops
from item 1 to 2 to 4 to 7 to 11 before giving the error. What goes wrong?


Sub LoopThroughCombo()

Dim i As Integer
Dim j As Integer

ActiveChart.DropDowns(1).ListIndex = 1
i = 0
j = UBound(ActiveChart.DropDowns(1).List)
MsgBox "j = " & j
For i = 0 To j - 1

'CommandBars("Custom").Controls(1).List (4) < "View News"
ActiveChart.DropDowns(1).ListIndex = ActiveChart.DropDowns(1).Value + i
'Charts(1).DropDowns(1).ListIndex = i + 1
MsgBox ActiveChart.DropDowns(1).Value & " - " &
ActiveChart.DropDowns(1).ListIndex
Next
' Call UpdateChart(ListIndex)
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Problem looping through combobox

with ActiveChart.Dropdowns(1)
for i = 1 to .Listcount
.ListIndex = i
MsgBox .Value & " - " & _
.ListIndex
Next
End With

I assume you don't have a macro assigned to the Dropdown.

--
Regards,
Tom Ogilvy


"Martin Los" wrote in message
...
I have a chartsheet with a combobox. I want to loop through the combobox

that
has 15 items. However the following macro gives an error "1004". It loops
from item 1 to 2 to 4 to 7 to 11 before giving the error. What goes wrong?


Sub LoopThroughCombo()

Dim i As Integer
Dim j As Integer

ActiveChart.DropDowns(1).ListIndex = 1
i = 0
j = UBound(ActiveChart.DropDowns(1).List)
MsgBox "j = " & j
For i = 0 To j - 1

'CommandBars("Custom").Controls(1).List (4) < "View News"
ActiveChart.DropDowns(1).ListIndex = ActiveChart.DropDowns(1).Value + i
'Charts(1).DropDowns(1).ListIndex = i + 1
MsgBox ActiveChart.DropDowns(1).Value & " - " &
ActiveChart.DropDowns(1).ListIndex
Next
' Call UpdateChart(ListIndex)
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Problem looping through combobox

Dear Tom and Vacation´s Over:

You are both completely right in your comments. Thanks a 1.000.000!

Thanks to your comments I can get on with the work of copying to Powerpoint.

Martin

P.S. My holiday has indeed just ended and as you can see I can do with a
refresh course (grin)

"Tom Ogilvy" escribió:

with ActiveChart.Dropdowns(1)
for i = 1 to .Listcount
.ListIndex = i
MsgBox .Value & " - " & _
.ListIndex
Next
End With

I assume you don't have a macro assigned to the Dropdown.

--
Regards,
Tom Ogilvy


"Martin Los" wrote in message
...
I have a chartsheet with a combobox. I want to loop through the combobox

that
has 15 items. However the following macro gives an error "1004". It loops
from item 1 to 2 to 4 to 7 to 11 before giving the error. What goes wrong?


Sub LoopThroughCombo()

Dim i As Integer
Dim j As Integer

ActiveChart.DropDowns(1).ListIndex = 1
i = 0
j = UBound(ActiveChart.DropDowns(1).List)
MsgBox "j = " & j
For i = 0 To j - 1

'CommandBars("Custom").Controls(1).List (4) < "View News"
ActiveChart.DropDowns(1).ListIndex = ActiveChart.DropDowns(1).Value + i
'Charts(1).DropDowns(1).ListIndex = i + 1
MsgBox ActiveChart.DropDowns(1).Value & " - " &
ActiveChart.DropDowns(1).ListIndex
Next
' Call UpdateChart(ListIndex)
End Sub




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 279
Default Problem looping through combobox

From 7th grade math.
...(advantages of faterhood - constant reminders of "easy math")

1,2,4,7,11. 15
is a series where you are adding 1,2,3,4,5,....n to the previous number
so look at how your counter is being set

Looks like this is the culprit
ActiveChart.DropDowns(1).ListIndex = ActiveChart.DropDowns(1).Value + i

sets list index i higher than it was, try + 1(one) instead

ActiveChart.DropDowns(1).ListIndex = ActiveChart.DropDowns(1).Value + 1


"Martin Los" wrote:

I have a chartsheet with a combobox. I want to loop through the combobox that
has 15 items. However the following macro gives an error "1004". It loops
from item 1 to 2 to 4 to 7 to 11 before giving the error. What goes wrong?


Sub LoopThroughCombo()

Dim i As Integer
Dim j As Integer

ActiveChart.DropDowns(1).ListIndex = 1
i = 0
j = UBound(ActiveChart.DropDowns(1).List)
MsgBox "j = " & j
For i = 0 To j - 1

'CommandBars("Custom").Controls(1).List (4) < "View News"
ActiveChart.DropDowns(1).ListIndex = ActiveChart.DropDowns(1).Value + i
'Charts(1).DropDowns(1).ListIndex = i + 1
MsgBox ActiveChart.DropDowns(1).Value & " - " &
ActiveChart.DropDowns(1).ListIndex
Next
' Call UpdateChart(ListIndex)
End Sub

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
Looping Problem Paul Black Excel Programming 3 September 17th 05 09:59 AM
Looping problem Sleeping Bear Excel Programming 2 July 7th 05 07:41 PM
If Then Else looping problem Kieran1028[_12_] Excel Programming 1 November 11th 04 06:27 PM
complex looping problem Max Bialystock Excel Programming 16 April 10th 04 01:56 PM
Looping Problem Todd Huttenstine[_3_] Excel Programming 5 January 25th 04 12:51 AM


All times are GMT +1. The time now is 04:59 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"