+ Reply to Thread
Results 1 to 6 of 6

How to write a code within a loop to copy and paste rows on to another Sheet

  1. #1
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    How to write a code within a loop to copy and paste rows on to another Sheet

    Hello,

    I was hoping someone could help.

    I have this loop set up and I want to copy and paste a row if my condition is met on to another sheet.

    I've don't need the whole row to be selected, just a certain range--(Like columns A-J)

    I've attached the spreadsheet.

    here is the code 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: How to write a code within a loop to copy and paste rows on to another Sheet

    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.

    The fastest and most efficient way I know of doing this is to use an Advanced Filter with the relevant criteria, copying the rows that meet the condition to your other sheet.
    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
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    Re: How to write a code within a loop to copy and paste rows on to another Sheet

    Quote Originally Posted by Richard Buttrey View Post
    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.

    The fastest and most efficient way I know of doing this is to use an Advanced Filter with the relevant criteria, copying the rows that meet the condition to your other sheet.
    Ok, I'll try and search YouTube for some advance filter tutorials to see if I can figure out the code.

    It's just that I am more comfortable with looping because I can set multiple conditions within the loop.

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: How to write a code within a loop to copy and paste rows on to another Sheet

    I do agree with Richard's comments. But if you only have a few rows of data (say < 1000) then the slower speed of looping isn't necessarily noticeable.
    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 03-23-2014 at 04:27 PM.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  5. #5
    Forum Contributor
    Join Date
    03-14-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    491

    Re: How to write a code within a loop to copy and paste rows on to another Sheet

    Quote Originally Posted by AlphaFrog View Post
    I do agree with Richard's comments. But if you only have a few rows of data (say < 1000) then the slower speed of looping isn't necessarily noticeable.
    Please Login or Register  to view this content.

    THANK YOU SO MUCH FOR THE CODE! I will mark this solved!

  6. #6
    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: How to write a code within a loop to copy and paste rows on to another Sheet

    Quote Originally Posted by swade730 View Post
    Ok, I'll try and search YouTube for some advance filter tutorials to see if I can figure out the code.

    It's just that I am more comfortable with looping because I can set multiple conditions within the loop.
    You can equally set multiple conditions with a filter.

+ 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. Code to write formula in 2 cells, copy, paste values, repeat next row until end of sheet
    By Oly Steel Man in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-14-2013, 11:13 AM
  2. Copy and paste as values in vba loop code
    By Kakkmaddafakka in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-15-2012, 08:24 AM
  3. [SOLVED] Loop copy and paste in new sheet
    By tonnerre2000 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-18-2012, 12:22 AM
  4. Copy and Paste Rows For certain condition then loop
    By steve70070 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-14-2011, 06:05 PM
  5. Loop to copy rows and paste into worksheet
    By damien_carr1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-01-2009, 06:10 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