Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 2 of 2

Thread: Stoping a Do While....Loop clause

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Posts
    101
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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. #2
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Sunny, spring-like Hull
    Posts
    3,339
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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 ]

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •