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 with exception

hello,
Any body would know how to do this?

For i=1 to 123
blablabla
next

But without doing certain values of i (lets say 50,60,70)

I could write
For i = 1 to 49
blablabla
next
for i=51 to 59
blablabla
next

but is there a more elegant way?
thanks
--
caroline
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default For.. Next with exception

You could do it two ways.

1.) You could use an If...Then statement inside your loop.

Dim i As Long

For i = 1 To 123
If i = 50 Or i = 60 Or i = 70 Then
' do something
End If
Next i

2.) You could list the i's you want to loop through.

Dim MyArray As Variant

MyArray = Split(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

For i = LBound(MyArray) To UBound(MyArray)
' do something
Next i


Hope this helps! If so, let me know, click "YES" below.
--
Cheers,
Ryan


"caroline" wrote:

hello,
Any body would know how to do this?

For i=1 to 123
blablabla
next

But without doing certain values of i (lets say 50,60,70)

I could write
For i = 1 to 49
blablabla
next
for i=51 to 59
blablabla
next

but is there a more elegant way?
thanks
--
caroline

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default For.. Next with exception

Public Sub OmitLoopIncrements()

Dim Index As Long

For Index = 1 To 123
Select Case Index
Case 50, 60, 70
Case Else
'your code
End Select
Next Index

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
sum of rows with exception of row x, y, z... lydia's Excel Discussion (Misc queries) 6 September 5th 09 03:54 PM
Exception from HRESULT: 0x800A03EC - COM Exception Unhandled Karthizen[_2_] Excel Programming 3 March 16th 09 09:54 PM
Exception list Gene Straub Excel Discussion (Misc queries) 2 January 28th 09 10:46 PM
Out of memory exception [email protected] Excel Programming 2 March 28th 07 04:46 AM
WHAT ARE THE CAUSES FOR 'EXCEPTION ERROR ' CAPTGNVR Excel Discussion (Misc queries) 0 January 29th 07 06:04 PM


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