How to exit the loop?

E

Eric

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
 
E

Eric

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
 
D

Dave Peterson

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top