+ Reply to Thread
Results 1 to 10 of 10

VBA loop finding an incorrect LastRow

  1. #1
    Forum Contributor
    Join Date
    09-21-2016
    Location
    UK
    MS-Off Ver
    2016
    Posts
    131

    VBA loop finding an incorrect LastRow

    Hello all,

    I have got a problem where loop is finding an incorrect last row and therefor instead of inserting values in the right row it inserts into a completely different row.

    VBA is meant to loop through the website links in sheet called web_links and return data from website in consecutive order inside sheet Sheet1 without leaving any gaps between the webX loops. As you can see there is data from a first link ending on row number 127 and then data from second link only starts at row number 254 third link starts at 734. So there are huge gaps in between. What am I missing on? Where the logic is not right in the code?

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA loop finding an incorrect LastRow

    Do you know how many rows of data you are getting from the site each time?

    Also, is the 10000 here arbitrary?
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    09-21-2016
    Location
    UK
    MS-Off Ver
    2016
    Posts
    131

    Re: VBA loop finding an incorrect LastRow

    The number of data rows is different on each link. You can find link with only 5 rows and find link with over couple of hundreds of rows. I dont think this what is causing this glitch to happen.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA loop finding an incorrect LastRow

    That's not really what I'm suggesting, what I'm thinking is that if you know the no of rows of actual data you will have then you should be able to work out the next row to put data in.

    For example if I started in row 2 and added 150 rows of data I can work out that the next row for data is row 152.

    If I then add 47 rows of data starting at row 152 I know the next row for data is 199 and so on.

  5. #5
    Forum Contributor
    Join Date
    09-21-2016
    Location
    UK
    MS-Off Ver
    2016
    Posts
    131

    Re: VBA loop finding an incorrect LastRow

    Apologies. But anyway, links do not have a set amount of rows.

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA loop finding an incorrect LastRow

    Try:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  7. #7
    Forum Contributor
    Join Date
    09-21-2016
    Location
    UK
    MS-Off Ver
    2016
    Posts
    131

    Re: VBA loop finding an incorrect LastRow

    Thank you very much! Obviously variable i was not being reset after the loop has finished. Genius! Worked like a charm.

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA loop finding an incorrect LastRow

    You're welcome and thanks for the rep!

    BTW - did you notice the new replace code?

  9. #9
    Forum Contributor
    Join Date
    09-21-2016
    Location
    UK
    MS-Off Ver
    2016
    Posts
    131

    Re: VBA loop finding an incorrect LastRow

    Thank for update. Haven't actually noticed that. Appreciate it.

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA loop finding an incorrect LastRow

    Welcome again!

+ 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. LastRow/Column to do Loop
    By dweebz in forum Excel Programming / VBA / Macros
    Replies: 36
    Last Post: 05-24-2016, 10:21 PM
  2. R1C1 lastRow not lastRow when data combined
    By Spyderwoman in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-28-2016, 05:20 PM
  3. [SOLVED] LastRow - for next loops longer than lastrow?
    By flabb in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-07-2016, 12:39 PM
  4. Replies: 5
    Last Post: 12-02-2012, 06:20 PM
  5. Loop keeps grabbing incorrect cell data
    By Iwasiw35 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-28-2011, 07:22 PM
  6. Copy From LastRow to LastRow+7
    By dvent in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-11-2010, 06:56 AM
  7. Lookup formula finding incorrect results
    By burnsie in forum Excel General
    Replies: 3
    Last Post: 11-03-2009, 09:47 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