Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2008

Tip: Looking for answers? Try searching our database.

How to exit the loop?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Eric - 16 Mar 2008 14:19 GMT
Does anyone have any suggestions on how to exit the loop if mycell.Text =""?
When myCell.Text is equal to "", the loop keeps going, but I would like to
exit the loop if myCell.Text is nothing or "".
Does anyone have any suggestions on how to code it?
Thanks in advance for any suggestions
Eric

Dim myRng As Range
Dim myCell As Range

For Each myCell In myRng.Cells
On Error Resume Next
Mywebsite = myCell.Text
On Error GoTo 0
' Perform task
Next myCell
Mike H - 16 Mar 2008 14:27 GMT
Eric

Put this ijn the loop

If myCell.Text = "" Then Exit For

Mike

> Does anyone have any suggestions on how to exit the loop if mycell.Text =""?
> When myCell.Text is equal to "", the loop keeps going, but I would like to
[quoted text clipped - 12 lines]
> ' Perform task
> Next myCell
Eric - 16 Mar 2008 16:14 GMT
Thank you very much for your suggestion
What about if myCell.Text is equal to "", then skip this one  and work on
the next one? Does anyone have any suggestions on how to code it?
On the other hands, if any web link fails to access the page due to traffic
jam, the macro will be stopped and point to following line,
.Refresh BackgroundQuery:=False
Do you have any suggestions on how to skip this error and keep on for the
next one? Therefore the loop will keep going.
Thank you very much for your suggestions
Eric

> Eric
>
[quoted text clipped - 20 lines]
> > ' Perform task
> > Next myCell
Dave Peterson - 16 Mar 2008 18:00 GMT
Dim myRng As Range
Dim myCell As Range

For Each myCell In myRng.Cells
 Mywebsite = myCell.Text
 if trim(mycell.text) = "" then
   'skip it
 else
   on error resume next
   'Perform task
   on error goto 0
 end if
Next myCell

You may want to share more of the code to get better answers.

> Thank you very much for your suggestion
> What about if myCell.Text is equal to "", then skip this one  and work on
[quoted text clipped - 31 lines]
> > > ' Perform task
> > > Next myCell

Signature

Dave Peterson

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.