+ Reply to Thread
Results 1 to 13 of 13

Select a Row with a value and copy and paste it

  1. #1
    Forum Contributor
    Join Date
    11-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    200

    Select a Row with a value and copy and paste it

    I need a macro that will select every row in sheet 1 that has a value >1 in column H and paste every one of those entire rows in sheet 2 in the next available row. Thank you!

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Select a Row with a value and copy and paste it

    Try this:

    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Select a Row with a value and copy and paste it

    Maybe:

    Please Login or Register  to view this content.

  4. #4
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Select a Row with a value and copy and paste it

    Another option, if you have a lot of data and don't want to loop through thousands of rows copying and pasting each, would be to use an advanced filter. Normally Advanced Filter won't let you copy the filtered data to a different worksheet, but through VBA it will.

    Let's say your data is in columns A:M, with headers in row 1. If the header in H1 is Length, then in an empty cell to the right of your data (like P1) type Length. In P2 type >1

    This will be used as the CriteriaRange for the Advanced Filter. On Sheet2, select cells A1:M1 and assign a name to that range, like "FilteredData". You can then use the following code to almost instantly filter the sought after data and have it appear on Sheet2:
    Please Login or Register  to view this content.
    Note: This will overwrite anything in Sheet2 A1:Mxx. If you routinely append data to an already existing list on Sheet2, you could still do this but would need a couple extra lines of code to get the last used row.

  5. #5
    Forum Contributor
    Join Date
    11-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    200

    Re: Select a Row with a value and copy and paste it

    That is virtually amazing and perfect! However, my data in row 1 can not be copied over and my headers are in row 2. What change would i need to make? Thanks!

  6. #6
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Select a Row with a value and copy and paste it

    Should be able to change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Make sure the named range ("FilteredData") is A2:M2 on Sheet2, rather than A1:M1.

  7. #7
    Forum Contributor
    Join Date
    11-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    200

    Re: Select a Row with a value and copy and paste it

    Thank you sooooooo much!

  8. #8
    Forum Contributor
    Join Date
    11-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    200

    Re: Select a Row with a value and copy and paste it

    One last thing, since my sheet 1 will have hundreds, thousands of lines, how can I get it to end up on a cell that has one of the selected dates in it? The reason is, since I have it set to turn the auto filter off, it finishes clear at the top in row 2 (I have that line froze). I do not want to have to scroll down hundreds,thousands of lines to get back to where I was at. I hope that makes sense?!

  9. #9
    Forum Contributor
    Join Date
    11-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    200

    Re: Select a Row with a value and copy and paste it

    Or it could just find the last cell in column a that has data in it.

  10. #10
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Select a Row with a value and copy and paste it

    If you want to select a cell on the sheet with the original data, you could just re-use the variable last and go to that cell.
    Please Login or Register  to view this content.
    That will select the last used cell in column A (based on the previously stored value of "last".

  11. #11
    Forum Contributor
    Join Date
    11-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    200

    Re: Select a Row with a value and copy and paste it

    That is not working. It gives an run-time error. I think it is cuz it is just coming back from sheet 2 and does not have value for last for sheet 1. ??

  12. #12
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Select a Row with a value and copy and paste it

    I don't know your worksheet names or layouts, so simply Activate the sheet you want and select the "last" cell in whichever column you want. If the variable "last" was calculated on a different sheet than the one you want to end up looking at, re-calculate "last" at the end of the code for the new sheet.
    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    11-25-2013
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    200

    Re: Select a Row with a value and copy and paste it

    you are amazing! thanks!

+ 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. select and copy paste special
    By max_max in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-09-2013, 09:55 AM
  2. How to select cell C1, copy paste then C2, copy paste then C3 etc
    By s45yth in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-07-2011, 07:15 AM
  3. Seach, Copy, select paste location, paste using macros
    By helpdave in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-16-2010, 11:36 PM
  4. select, copy, paste into new row
    By artromanov in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-27-2007, 04:56 AM
  5. [SOLVED] Select copy and paste
    By David Rose in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-13-2005, 01:06 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