+ Reply to Thread
Results 1 to 3 of 3

How to stop the for loop?

Hybrid View

  1. #1
    Registered User
    Join Date
    09-16-2008
    Location
    malaysia
    Posts
    89

    How to stop the for loop?

    hi all, i am facing another problem here.

    i want to stop a for loop.

    i attach my excile file at here.
    it is call as parent if the column "a" is blank n hv alphabet.
    if the column "a" is not blank n hv numberic it is call as child.
    i want to delete the child if the parent come out a word "mount"


    here are my code

    
    Sub aa()
      
     r = ActiveSheet.UsedRange.Rows.Count
     For i = 1 To r - 1
        If InStr(3, Cells(i, 3).Value, "MOUNT") > 0 Then
        z = i + 1
     
        For z = 1 To r - 1
          If Cells(z, "a").Value <> "" Then
          Rows(z).Select
          Selection.Delete Shift:=xlUp
           'ElseIf Cells(z, "a").Value = "" Then
           'stop this for loop and go to find another parent whether hv mount -- this part how to write --
        End If
        
          Next
          
        End If
      Next i
    End Sub
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    09-19-2008
    Location
    It varies ...
    MS-Off Ver
    Office365 - 64bit
    Posts
    862
    Hi - although I don't follow exactly what you're trying to do, to exit a loop on a condition met within the loop I use a GoTo like:

    Sub aa()
        r = ActiveSheet.UsedRange.Rows.Count
        For i = 1 To r - 1
            If InStr(3, Cells(i, 3).Value, "MOUNT") > 0 Then
                z = i + 1
                For z = 1 To r - 1
                    If Cells(z, "a").Value <> "" Then
                        Rows(z).Select
                        Selection.Delete Shift:=xlUp
                    ElseIf Cells(z, "a").Value = "" Then
                        GoTo ExitLoop
                    End If
                Next z
    ExitLoop:
            End If
        Next i
    End Sub
    Hope that helps. MM
    MatrixMan.
    --------------------------------------
    If this - or any - reply helps you, remember to say thanks by clicking on *Add Reputation.
    If your issue is now resolved, remember to mark as solved - click Thread Tools at top right of thread.

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Use

    Exit For
    Put it where the condition is met.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Use Event Procedure and OnTime to Stop a Macro
    By Protiusmime in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-26-2008, 07:46 PM
  2. Stop a running macro
    By Frank e in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-18-2008, 02:07 PM
  3. how to stop pivotTable?
    By Mohsin in forum Excel General
    Replies: 0
    Last Post: 04-25-2007, 04:37 AM
  4. Stop all macro's
    By RickBartels in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-08-2007, 06:55 AM
  5. Stop relation between two sheets
    By Dipwind in forum Excel General
    Replies: 5
    Last Post: 12-08-2006, 02:27 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1