+ Reply to Thread
Results 1 to 12 of 12

how to stop this loop....

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-23-2012
    Location
    hyderabad
    MS-Off Ver
    Excel 2016
    Posts
    210

    how to stop this loop....

    Hi,

    Below is my script and its not stopping once the data is over.....Please help me on this and correct me where I am going wrong

     
    Sub test()
    
    Dim row As Long
        row = 2
        
        Range("K2").Select
        
        Do
        ActiveCell.Offset(0, 1).Select
        ActiveCell.FormulaR1C1 = "=+RC[-11]"
        ActiveCell.Offset(0, -1).Select
        Selection.End(xlDown).Select
        
     Loop Until Cells(row, 3) = "Powered by GL Compliance Manager"
    
    End Sub
    Last edited by vimalanathk; 12-03-2013 at 01:13 AM.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: how to stop this loop....

    Hi, vimalanathk,

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: how to stop this loop....

    Hi, vimalanathk,,

    you compare the contents of Range(C2) constantly - is this calculated by formula or a constant value found in Column C? Maybe try it like this or post a sample of your workbook:
    Sub test()
    
    Range("K2").Select
    
    Do Until Cells(ActiveCell.row, 3) = "Powered by GL Compliance Manager"
      With ActiveCell
        .Offset(0, 1).FormulaR1C1 = "=+RC[-11]"
        .End(xlDown).Select
      End With
    Loop
    
    End Sub
    Alternative code:
    Sub test2()
    Dim rngFound As Range
    
    Set rngFound = Columns(3).Find(what:="Powered by GL Compliance Manager", LookAt:=xlWhole)
    If Not rngFound Is Nothing Then
      Range("L2:L" & rngFound.row).FormulaR1C1 = "=RC[-11]"
    End If
    
    Set rngFound = Nothing
    
    End Sub
    You should consider any other variable as Row is part of the VBA vocabulary.

    Ciao,
    Holger
    Last edited by HaHoBe; 12-03-2013 at 01:31 AM.

  4. #4
    Forum Contributor
    Join Date
    07-23-2012
    Location
    hyderabad
    MS-Off Ver
    Excel 2016
    Posts
    210

    Re: how to stop this loop....

    I tried all the codes given in replies but the loop is not stopping and its going to end of excel sheet.

    Please find the example sheet of my data and help me on the same.

    Regards,
    Vimala K
    Attached Files Attached Files

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: how to stop this loop....

    Hi, Vimala K,

    no need for any loop IMO:
    Sub EF972535()
    On Error Resume Next
    Range("K2:K" & Range("K" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeConstants, 23).Offset(0, 1).FormulaR1C1 = "=RC[-11]"
    If Err <> 0 Then
      MsgBox "No cells in Column K as constants"
    End If
    End Sub
    @Fonzie:
    I doubt your code is taking care of Column K being filled?

    Ciao,
    Holger

  6. #6
    Registered User
    Join Date
    02-13-2013
    Location
    Bergen County
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: how to stop this loop....

    Thanks Ciao Holger!

    Vimalanathk,
    Try out this code.

    Sub test()
    Dim row As Long
    row = 2
    Do
        If Cells(row, 1).Value <> "x" And Cells(row, 1).Value <> "" Then
            Cells(row, 12).Value = "=+RC[-11]"
        End If
        row = row + 1
    Loop Until Cells(row, 3).Value = "Powered by GL Compliance Manager"
    End Sub
    Thanks,
    Fonzie
    Last edited by fonzie29; 12-03-2013 at 02:45 AM.

  7. #7
    Forum Contributor
    Join Date
    07-23-2012
    Location
    hyderabad
    MS-Off Ver
    Excel 2016
    Posts
    210

    Re: how to stop this loop....

    Your bottom code is giving me the output for blank line of status columns also where i need the out put only the status is updated... it should be blank for status blank line items.

    Regards,
    Vimala K

  8. #8
    Registered User
    Join Date
    02-13-2013
    Location
    Bergen County
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: how to stop this loop....

    Hi,
    Not sure exactly what you are trying to do but I'm assuming that you want to copy down a formula until you find the word "Powered by GL Compliance Manager" in another column assuming its column L.
    Try this if you want the formula to be next to column K.

    Sub test()
    Dim row As Long
    row = 2
    Do
    Cells(row, 12).value = "=+RC[-11]"
    row = row + 1
    Loop Until Cells(row, 11).value = "Powered by GL Compliance Manager"
    End Sub
    Thanks,
    Fonzie

  9. #9
    Registered User
    Join Date
    02-13-2013
    Location
    Bergen County
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: how to stop this loop....

    This should do it based on the file you provided.

    Sub test()
    Dim row As Long
    row = 2
    Do
    Cells(row, 12).value = "=+RC[-11]"
    row = row + 1
    Loop Until Cells(row, 3).value = "Powered by GL Compliance Manager"
    End Sub
    Thanks,
    Fonzie

  10. #10
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: how to stop this loop....

    Hi,

    Attached is my solution. Hope this helps.
    Attached Files Attached Files
    Happy Computing ,

    Xlbiznes.

    To show your appreciation please click *

  11. #11
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: how to stop this loop....

    Just a side note on your original code, the code doesn't stop because you did not increment row variable so it's forever looking at row 2.

+ 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. Loop Does Not Stop
    By ryanmorris in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-14-2011, 07:31 PM
  2. Can't get my loop to stop!!
    By berlinhammer in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-31-2009, 03:04 AM
  3. Loop until won't stop!?
    By meacho in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-27-2007, 03:37 PM
  4. Hot key to stop a LOOP
    By joopdog in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-09-2006, 02:51 PM
  5. Stop a loop
    By Matthew McManus in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-11-2005, 04:55 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