Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Go straight to next value in a For... Next loop

Is there a way of going straight to the next value in a For / Next loop,
having tested the current value? I need to do something like this (for
example):

Dim c as Range
For each c in Selection.Cells
If c.Value < 100 Then
Goto Next c '<<<<< I know this is illegal, but it illustrates
what I want to do!
Else
{statements where c.Value = 100}
...
...
End If
Next c

I don't want to Exit For, I just want it to effectively ignore the current
instance of c and move onto the next. I've tried "Next c" but it generates a
compile error.

Thanks in advance.

Ian


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Go straight to next value in a For... Next loop

What you have (without the goto of course) does just that, because the fact
that c.value < 100 means that all of the code in the Else portion does not
get executed, so the next statement is EndIf, which drops into the Next.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"IanKR" wrote in message
...
Is there a way of going straight to the next value in a For / Next loop,
having tested the current value? I need to do something like this (for
example):

Dim c as Range
For each c in Selection.Cells
If c.Value < 100 Then
Goto Next c '<<<<< I know this is illegal, but it illustrates
what I want to do!
Else
{statements where c.Value = 100}
...
...
End If
Next c

I don't want to Exit For, I just want it to effectively ignore the current
instance of c and move onto the next. I've tried "Next c" but it generates
a compile error.

Thanks in advance.

Ian



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 324
Default Go straight to next value in a For... Next loop

I would construct it this way.

Dim c as Range
For each c in Selection.Cells
If c.Value 100 Then
Do the job
end if
Next c

This way is c is less than 100, it will jump to the "Next c" line and proceed.
--
Best wishes,

Jim


"IanKR" wrote:

Is there a way of going straight to the next value in a For / Next loop,
having tested the current value? I need to do something like this (for
example):

Dim c as Range
For each c in Selection.Cells
If c.Value < 100 Then
Goto Next c '<<<<< I know this is illegal, but it illustrates
what I want to do!
Else
{statements where c.Value = 100}
...
...
End If
Next c

I don't want to Exit For, I just want it to effectively ignore the current
instance of c and move onto the next. I've tried "Next c" but it generates a
compile error.

Thanks in advance.

Ian



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Go straight to next value in a For... Next loop

check out this structu

Sub demo()
For Each c In Selection
If c.Value < 100 Then
Else
msbgox ("time to do something")
End If
Next
End Sub


if the value is less than 100 we do absolutely nothing exept move on to the
next c
--
Gary''s Student
gsnu200707


"IanKR" wrote:

Is there a way of going straight to the next value in a For / Next loop,
having tested the current value? I need to do something like this (for
example):

Dim c as Range
For each c in Selection.Cells
If c.Value < 100 Then
Goto Next c '<<<<< I know this is illegal, but it illustrates
what I want to do!
Else
{statements where c.Value = 100}
...
...
End If
Next c

I don't want to Exit For, I just want it to effectively ignore the current
instance of c and move onto the next. I've tried "Next c" but it generates a
compile error.

Thanks in advance.

Ian



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 857
Default Go straight to next value in a For... Next loop

Dim c as Range
For each c in Selection.Cells
If c.Value < 100 Then
'Do Nothing
Else
{statements where c.Value = 100}
...
...
End If
Next c


"IanKR" wrote:

Is there a way of going straight to the next value in a For / Next loop,
having tested the current value? I need to do something like this (for
example):

Dim c as Range
For each c in Selection.Cells
If c.Value < 100 Then
Goto Next c '<<<<< I know this is illegal, but it illustrates
what I want to do!
Else
{statements where c.Value = 100}
...
...
End If
Next c

I don't want to Exit For, I just want it to effectively ignore the current
instance of c and move onto the next. I've tried "Next c" but it generates a
compile error.

Thanks in advance.

Ian





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Go straight to next value in a For... Next loop

Is there a way of going straight to the next value in a For / Next
loop, having tested the current value? I need to do something like
this (for example):

Dim c as Range
For each c in Selection.Cells
If c.Value < 100 Then
Goto Next c '<<<<< I know this is illegal, but it
illustrates what I want to do!
Else
{statements where c.Value = 100}
...
...
End If
Next c

I don't want to Exit For, I just want it to effectively ignore the
current instance of c and move onto the next. I've tried "Next c" but
it generates a compile error.

Thanks in advance.

Ian


Many thanks for all your replies. I feel pretty stupid now - such a simple
solution!


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 324
Default Go straight to next value in a For... Next loop

Nothing to feel stupid about. Sometimes the simplest fixes are the hardest
to see. We expect everything to be complicated and overlook the simple
things.

Welcome to the club!
--
Best wishes,

Jim


"IanKR" wrote:

Is there a way of going straight to the next value in a For / Next
loop, having tested the current value? I need to do something like
this (for example):

Dim c as Range
For each c in Selection.Cells
If c.Value < 100 Then
Goto Next c '<<<<< I know this is illegal, but it
illustrates what I want to do!
Else
{statements where c.Value = 100}
...
...
End If
Next c

I don't want to Exit For, I just want it to effectively ignore the
current instance of c and move onto the next. I've tried "Next c" but
it generates a compile error.

Thanks in advance.

Ian


Many thanks for all your replies. I feel pretty stupid now - such a simple
solution!



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default Go straight to next value in a For... Next loop

Thanks, Jim.

I've been using VBA for about 4 years, now, and have recently got to the
point where I can (usually) write code fairly quickly to do what I want. OK,
it may not be the most elegant or the quickest, but it works! But
occasionally something really simple like this completely stumps me! As you
say, very often it's the simplest solution that works. Sometimes we just
can't see the wood for the trees.

Nothing to feel stupid about. Sometimes the simplest fixes are the
hardest
to see. We expect everything to be complicated and overlook the simple
things.

Welcome to the club!
--
Best wishes,

Jim



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
Straight line depreciation Ian Excel Worksheet Functions 4 August 26th 09 05:47 PM
Straight Line is not straight klm Excel Discussion (Misc queries) 2 September 13th 07 07:19 PM
straight line graph, really straight line.. Jason Excel Discussion (Misc queries) 2 July 20th 06 10:08 PM
best fit straight line Priscilla Charts and Charting in Excel 1 May 17th 06 11:32 AM
I want a straight answer Terry Excel Worksheet Functions 5 January 26th 06 10:29 AM


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

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"