+ Reply to Thread
Results 1 to 6 of 6

Loop to copy rows of data to another sheet if version number is higher

  1. #1
    Registered User
    Join Date
    07-12-2015
    Location
    Melbourne,Australia
    MS-Off Ver
    2007
    Posts
    14

    Loop to copy rows of data to another sheet if version number is higher

    Hi,

    I am having trouble with a macro to do the following.
    Search the Version column of the OldSheet for the latest Version. Search the Version column in the NewSheet for the latest Version. Copy any Versions from the OldSheet (and the cells next to it containing text) and insert it in the NewSheet. I have this working easily if the OldSheet is only 1 version higher than the NewSheet, it simply just searched the column for the next blank space and then went up 1 row and copied data. This will normally work fine although sometimes the OldSheet will be more than 1 Version ahead of NewSheet. In this case it only copies the latest (e.g. NewSheet may have up to Version 0.10, but OldSheet goes up to 0.13, the Macro only copies 0.13 so NewSheet would show 0.8, 0.9, 0.10, 0.13). I need it to copy all of the new Versions.

    Below is the code, I know I need to put a loop in somewhere but I am having trouble and seem to screw the macro every time I do that. Have attached a worksheet to show what I mean as well.

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

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Loop to copy rows of data to another sheet if version number is higher

    This question really should be a FAQ. I see it time and time again and looping just isn't the best way of doing this sort of thing.

    Whenever you find yourself creating a loop step back a bit and consider if there isn't a more efficient way. Loops should only be used as a last resort since they can be very slow particularly when many rows are involved.

    I believe the fastest and most efficient way of doing this will be to use a Data Filter using the relevant criteria.

    That said please add the expected results you want to see so that we can better advise.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    07-12-2015
    Location
    Melbourne,Australia
    MS-Off Ver
    2007
    Posts
    14

    Re: Loop to copy rows of data to another sheet if version number is higher

    Quote Originally Posted by Richard Buttrey View Post
    That said please add the expected results you want to see so that we can better advise.
    Currently NewSheet goes up to 0.10, the Macro I have at the moment will grab the bottom value from OldSheet and insert it at the bottom of NewSheet. The problem is this will mean NewSheet goes from 0.10 to 0.13, it does not copy across 0.11 and 0.12.

    I am expecting NewSheet to copy across any data from OldSheet that has a higher Version than itself, so in this example NewSheet should copy across 0.11, 0.12 and 0.13. Hopefully that makes sense.

  4. #4
    Registered User
    Join Date
    07-12-2015
    Location
    Melbourne,Australia
    MS-Off Ver
    2007
    Posts
    14

    Re: Loop to copy rows of data to another sheet if version number is higher

    Tried looking into Data Filters as suggested above and feel even more lost now. Any advice?

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Loop to copy rows of data to another sheet if version number is higher

    If you manually create the table of results that you expect to derive and clearly explain in a note how you've arrived at the table, i.e. your rules, then I'll take a look later.

  6. #6
    Registered User
    Join Date
    07-12-2015
    Location
    Melbourne,Australia
    MS-Off Ver
    2007
    Posts
    14

    Re: Loop to copy rows of data to another sheet if version number is higher

    This is how it currently works, NewSheet has up to Version 0.10:
    CurrentNew.JPG
    When I run the macro it grabs the last figure from OldSheet and adds it to the bottom of NewSheet
    OldSheet has up to Version 0.13
    CurrentOld.JPG
    After running Macro Version 0.13 get's copied to NewSheet but not 0.11 & 0.12
    NewNew.JPG

    What I want is the Macro to ALSO copy 0.11 & 0.12 but have this occur for any number, e.g. so if NewSheet only went to 0.8 it would copy 0.9 - 0.13 from OldSheet.

    Hopefully that makes sense.

    Test.xlsm

+ 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. [SOLVED] Copy data from one sheet to another if the date is equal or higher than a gien date
    By ANDREAAS in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-08-2013, 02:57 PM
  2. Replies: 3
    Last Post: 03-27-2013, 03:58 PM
  3. Within a loop, need to copy all rows from one sheet to another upon matching criteria
    By ripvanbrown in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-17-2012, 03:52 PM
  4. loop that copy rows to new sheet
    By ALLEYCAT38 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 04-27-2012, 01:47 AM
  5. Loop to copy rows to another sheet if value not contained in both
    By hotrod6657 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-24-2011, 08:21 AM
  6. Replies: 7
    Last Post: 03-22-2010, 05:22 PM
  7. [SOLVED] Hiding rows:hide and unhide if any number higher than 0 is entered
    By not bright in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 04-14-2006, 05:35 PM
  8. loop to copy selected rows to a new sheet
    By katey in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-08-2005, 10:01 PM

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