Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Simple question on For...Next loop

Hello.

This should be easy for the pros of the list

I am used to writing For...Next loops as...

For i = 1 to 10

.... and sometimes using the Step 2 to not move up by increments of 1.

How do I use the loop structure for an eclectic bunch of numbers e.g.

1,2, 5,7, 12, 15,20

So for example I tried

For col = 1, 2, 5, 7, 12, 15, 20

....but VBA said 'no'.

I managed to do this by forming an array...but I am sure there is an easier
route.

Regards


Alex
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Simple question on For...Next loop

Hi Alex,

Sub Test2()

Dim arr As Variant
Dim i As Long

arr = Array(1, 2, 5, 7, 12, 15, 20)


For i = LBound(arr) To UBound(arr)
'do something. e.g.:
MsgBox arr(i)


Next

End Sub

---
Regards,
Norman



"Alex" wrote in message
...
Hello.

This should be easy for the pros of the list

I am used to writing For...Next loops as...

For i = 1 to 10

... and sometimes using the Step 2 to not move up by increments of 1.

How do I use the loop structure for an eclectic bunch of numbers e.g.

1,2, 5,7, 12, 15,20

So for example I tried

For col = 1, 2, 5, 7, 12, 15, 20

...but VBA said 'no'.

I managed to do this by forming an array...but I am sure there is an
easier
route.

Regards


Alex



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
simple loop needed please Alan Excel Discussion (Misc queries) 1 May 5th 10 06:33 PM
I need a simple loop with a 4+ row added in. pgarcia Excel Discussion (Misc queries) 5 July 19th 07 07:42 PM
Some help w/ simple loop, please? terry b Excel Programming 6 February 6th 05 06:17 PM
simple loop macro jim27[_2_] Excel Programming 0 October 17th 04 06:36 PM
simple loop macro jim27 Excel Programming 2 October 17th 04 06:28 PM


All times are GMT +1. The time now is 05:50 PM.

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

About Us

"It's about Microsoft Excel"