View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Leo Heuser Leo Heuser is offline
external usenet poster
 
Posts: 266
Default for next question

"Gary Keramidas" <GKeramidasATmsn.com skrev i en meddelelse
...
i know how to do this a few ways, but have a question.

is something like this possible?

for i = 1 to 3, 5 to 7

just curious because i thought i saw something somewhere, but i could be
mistaken.

--


Gary




Gary

Maybe this setup for shorter intervals:

Sub test()
'Leo Heuser, 20 Jan, 2007
Dim Counter As Long
Dim NumArray As Variant

NumArray = Array(1, 2, 3, 5, 6, 7)

For Counter = LBound(NumArray) To UBound(NumArray)
Debug.Print NumArray(Counter)
Next Counter

End Sub


Two more options for larger intervals:

Sub test2()
'Leo Heuser, 20 Jan, 2007
Dim Counter As Long
Dim LoopColl As Collection
Dim Num As Variant
Dim NumArray(1 To 3, 1 To 1) As Variant


NumArray(1, 1) = Evaluate("Row(1:3)")
NumArray(2, 1) = Evaluate("Row(5:7)")
NumArray(3, 1) = Evaluate("Row(20:50)")

Set LoopColl = New Collection

For Counter = LBound(NumArray) To UBound(NumArray)
For Each Num In NumArray(Counter, 1)
LoopColl.Add Item:=Num
Next Num
Next Counter

For Counter = 1 To LoopColl.Count
Debug.Print LoopColl(Counter)
Next Counter

End Sub


Sub test3()
'Leo Heuser, 20 Jan, 2007
Dim Counter As Long
Dim Dummy As Variant
Dim LoopColl As Collection
Dim Num As Variant
Dim NumArray As Variant

NumArray = Array(Array(1, 3), Array(5, 7), Array(20, 50))

Set LoopColl = New Collection

For Counter = LBound(NumArray) To UBound(NumArray)
Dummy = Evaluate("Row(" & _
NumArray(Counter)(LBound(NumArray(Counter))) & _
":" & NumArray(Counter)(UBound(NumArray(Counter))) & ")")
For Each Num In Dummy
LoopColl.Add Item:=Num
Next Num
Next Counter

For Counter = 1 To LoopColl.Count
Debug.Print LoopColl(Counter)
Next Counter

End Sub


--
Best regards
Leo Heuser

Followup to newsgroup only please.