![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Posts: 97
|
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 |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sunny, spring-like Hull
Posts: 3,339
|
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 ] |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|