Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 183
Default For Next (non consecutive values for i)

When using the For i = 1 to 10
€˜Your code
Next i

Can I define i = 1 to 10 (excluding certain values)?
I want the code to be executed only for i= 1,4,5,6,8,10

Thanks
--
caroline
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default For Next (non consecutive values for i)

for i = 1 to 10

Select Case i
case 1, 4, 5, 6, 8, 10

End Select

Next

--
Regards,
Tom Ogilvy

"caroline" wrote:

When using the For i = 1 to 10
€˜Your code
Next i

Can I define i = 1 to 10 (excluding certain values)?
I want the code to be executed only for i= 1,4,5,6,8,10

Thanks
--
caroline

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default For Next (non consecutive values for i)

Sub caroline()
s = Array(1, 4, 5, 6, 8, 10)
For i = LBound(s) To UBound(s)
MsgBox (s(i))
Next
End Sub

--
Gary''s Student - gsnu200724


"caroline" wrote:

When using the For i = 1 to 10
€˜Your code
Next i

Can I define i = 1 to 10 (excluding certain values)?
I want the code to be executed only for i= 1,4,5,6,8,10

Thanks
--
caroline

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default For Next (non consecutive values for i)

One way:

Dim vArr As Variant
Dim i As Long
Dim j As Long
vArr = Array(1,4,5,6,8,10)
For j = LBound(vArr) to UBound(varr)
i = vArr(j)
'Your code
Next j



In article ,
caroline wrote:

When using the For i = 1 to 10
€˜Your code
Next i

Can I define i = 1 to 10 (excluding certain values)?
I want the code to be executed only for i= 1,4,5,6,8,10

Thanks

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
matching consecutive values Matthew[_2_] Excel Discussion (Misc queries) 2 September 7th 09 10:54 PM
Count Consecutive Values The Question guy Excel Discussion (Misc queries) 7 October 29th 08 08:35 PM
Exclude #N/A values and Return Numeric values to consecutive cells in Single Row Sam via OfficeKB.com Excel Worksheet Functions 5 February 9th 08 03:07 AM
Return Consecutive Values - Pairs Sam via OfficeKB.com Excel Worksheet Functions 6 July 2nd 05 04:43 PM
Return Consecutive Values Sam via OfficeKB.com Excel Worksheet Functions 14 June 9th 05 01:21 AM


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