+ Reply to Thread
Results 1 to 4 of 4

VBA - Loop stops too soon

  1. #1
    Registered User
    Join Date
    10-08-2010
    Location
    North Yorkshire, England
    MS-Off Ver
    Excel 2003
    Posts
    69

    VBA - Loop stops too soon

    Could someone please let me know why this loop stops prematurely (row 105) i.e. before it reaches the cell with the text "STOP" in it (row 3000). It is trawling through a database copied into excel & copies the row (to another location) after the row that contains the text "Premises:"
    Thank you

    PHP Code: 
    Sub LoopThroughRows()
    Dim n As Integer
    Dim wsSource 
    As Worksheet
    Dim wsTarget 
    As Worksheet
    Dim row1 
    As Integer

    Set wsTarget 
    Sheets("Output")
    Set wsSource Sheets("Data")
    row1 1
    wsSource
    .Select

    'set n=2 to start in the second row
    n = 2
    '
    continue loop while the cell is not empty
    Do 
    Until Cells(n1) = "STOP"
    If Cells(n1).Text "Premises:" Then
    Cells
    (n1).Select

    ActiveCell
    .Offset(10).Select
    ActiveCell
    .EntireRow.Copy wsTarget.Cells(row11)
    row1 row1 1
    wsSource
    .Select

    End 
    If
    'move to next row
    n = n + 1
    '
    Stop
    Loop

    End Sub 

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: VBA - Loop stops too soon

    Try this untested code......

    Please Login or Register  to view this content.


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Registered User
    Join Date
    10-08-2010
    Location
    North Yorkshire, England
    MS-Off Ver
    Excel 2003
    Posts
    69

    Re: VBA - Loop stops too soon

    Thank you, that does the same, after a bit of tweaking however I found a fault with original database which caused the macro to stop at the specific point. Sorry to anyone if time was spent/wasted considering this non-existent problem!

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: VBA - Loop stops too soon

    No issues we are glad that you fixed it and thanks for the feedback too...

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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