Looping question

  • Thread starter Thread starter Jase
  • Start date Start date
J

Jase

I have a looping function that copies from a range and then pastes into
another. However I can't seem to get the function to end looping when I would
like. This is what I have to exit the loop and it does not work.

Do
If IsEmpty(RngToCopy) Then
Exit Sub
 
IsEmpty returns a True/False value indicating whether a variable has been
initialized. If your code is assigning a range to RngToCopy, then it has been
initialized and will return TRUE. If you want to test whether RngToCopy
contains anything, try

If Len(RngToCopy.Value) = 0 Then Exit Sub

Hope this helps,

Hutch
 
If rngtocopy is a single cell, then it should work.

But isempty() really checks to see if the cell is empty--no formula that
evaluates to "".

If you have a formula that evaluates to "", you could use:

if rngtocopy.value = "" then
exit sub

=======
If rngtocopy is multiple cells, then you might be able to use:

if application.counta(rngtocopy) = 0 then
'all are empty
exit sub

Again, if you have formulas that evaluate to "", then this won't work.
=Counta() will include the cells with formulas.
 

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

Similar Threads

LOOPING multiple ranges 1
PASTE SPECIAL w/ Macro 7
Select drop down menu option using libre-calc macro 0
For..Next..Loop 12
Marco Exits without error 1
PASTE SPECIAL 1
loop 16
Do loop 1

Back
Top