Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default for next question

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



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default for next question

There's no such structure in VBA. You'd have to simulate it:

For i = 1 to 7
If i < 4 Then
'Do stuff
End If
Next i

In article ,
"Gary Keramidas" <GKeramidasATmsn.com wrote:

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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default for next question

ok, thanks je.

--


Gary


"JE McGimpsey" wrote in message
...
There's no such structure in VBA. You'd have to simulate it:

For i = 1 to 7
If i < 4 Then
'Do stuff
End If
Next i

In article ,
"Gary Keramidas" <GKeramidasATmsn.com wrote:

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.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default for next question


Consider:

Sub aa()
For i = 1 To 7
' Within the For..Next loop this is overkill
' BUT the Select ... Case is clearer when handling exceptions
Select Case i
Case 1 To 3 ' or Case Is <= 3
'Code
Case 4
'Code
Case 5 To 7 ' or Case Is =5
'Code
Else
'Code
End Select
Next
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
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.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default for next question

thanks for the help. i've already done it with a few arrays. i just thought i
saw somewhere that somebody had done something like i posted. so, i guess i was
mistaken.

--


Gary


"Leo Heuser" wrote in message
...
"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.





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 266
Default for next question

"Gary Keramidas" <GKeramidasATmsn.com skrev i en meddelelse
...
thanks for the help. i've already done it with a few arrays. i just
thought i saw somewhere that somebody had done something like i posted.
so, i guess i was mistaken.

--


Gary


You're welcome.

Leo Heuser


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
Excel 2007 Macro/VB Question DDE Question MadDog22 Excel Worksheet Functions 1 March 10th 10 01:47 AM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good davegb Excel Programming 1 May 6th 05 06:35 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 0 April 27th 05 07:46 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 23 April 23rd 05 09:26 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 0 April 22nd 05 03:30 PM


All times are GMT +1. The time now is 08:32 AM.

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"