Stoping a Do While....Loop clause

huorsa

Board Regular
Joined
Feb 15, 2002
Messages
101
I have the following code:

Range("c2").Select
largo:
Do While Len(ActiveCell) < 3
ActiveCell.Value = ""
ActiveCell.Offset(1, 0).Activate
Loop
ActiveCell.Offset(1, 0).Activate
GoTo largo

The purrpose of the code is to check in colum C the cells that have less than 3 characters, if they have less than 3, the clear the cell. The column C only has 80 rows with information.

It works, the problem is that never stops, how can I make it to stop after the last cell with information or after 100 times.

Thanks

Hugo
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
It'll never stop because empty cells have a length of less than 3, hence it'll just keep on going. Without seeing your data, I couldn't say precisely how to get out of the loop (I don't know if you have any empty cells within your column), but you could use a counter within the loop and an Exit Do statement. Try adding the following inside your loop-

x= x + 1
If x > 100 then Exit Do

Add x= 0 before the start of the loop.

Also, I think you should remove your GoTo statement, otherwise the loop will carry on being run.
This message was edited by Mudface on 2002-02-23 12:10
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,251
Members
448,556
Latest member
peterhess2002

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top