+ Reply to Thread
Results 1 to 14 of 14

Copy marked rows to new sheet

  1. #1
    Registered User
    Join Date
    11-07-2011
    Location
    Germany
    MS-Off Ver
    Excel 2007
    Posts
    13

    Copy marked rows to new sheet

    I'm trying to get all the rows that are marked with an "x" in column B to be copied and placed into a new worksheet.

    I recorded the basic operation and got it doing what i'd like until the error "out of range" pops up (noted in code) :-/

    also, i want to remove the filter on the original sheet...

    The reason I want to do this in VBA is b/c i have a workbook with many worksheets and i'm eventually going to want this to run through each worksheet, doing the same thing automatically... is there a better way to go about it?

    thanks!!

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by lennoxem; 12-01-2011 at 04:23 AM.

  2. #2
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Copy marked rows to new sheet

    Hi,

    Try changing the sheet reference to index instead, like this
    And i've streamlined your code a bit

    Please Login or Register  to view this content.
    Please take time to read the forum rules

  3. #3
    Registered User
    Join Date
    11-07-2011
    Location
    Germany
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Copy marked rows to new sheet

    Great! It works as far as creating the new sheet, and naming it properly. However, now an error occurs when it tries to paste into the new sheet. Should I try to put this into option explicit? (esp. since the rest of the workbook this will be integrated into always has option explicit as well....) I'm not exactly sure how to do that...

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

  4. #4
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Copy marked rows to new sheet

    Change this

    Please Login or Register  to view this content.
    To
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-07-2011
    Location
    Germany
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Copy marked rows to new sheet

    the error now reads "application-defined or object-defined error" in the same place :-/

  6. #6
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Copy marked rows to new sheet

    Sorry my error

    Try this

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-07-2011
    Location
    Germany
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Copy marked rows to new sheet

    thanks for sticking with me

    the error is still in the same place in the code. I had to change the sheet reference number to 1 in the beginning, becuase at first, it is the first sheet. the timeline sheet is inserted at the beginning, which changes the reference number of any sheet that will follow it...

    Please Login or Register  to view this content.

  8. #8
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Copy marked rows to new sheet

    Your changing around the sheet references, what sheet holds the values to be copied and wich sheet should it be pasted on?

  9. #9
    Registered User
    Join Date
    11-07-2011
    Location
    Germany
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Copy marked rows to new sheet

    i know... it's confusing.... in the beginning, the sheet with the information is sheet 1, then when the new sheet is added, it becomes second because the new sheet is first. I tried it out like this:
    Please Login or Register  to view this content.
    and it tried to copy onto the sheet where it copied FROM in the first place...

  10. #10
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Copy marked rows to new sheet

    The try this instead

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    11-07-2011
    Location
    Germany
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Copy marked rows to new sheet

    awesome, the reference problem is solved, and i figured out the error as well... turns out this was the culprit:
    Please Login or Register  to view this content.
    ...

    Thank you for your help now to make it work in the real workbook....
    Last edited by lennoxem; 11-24-2011 at 08:09 AM.

  12. #12
    Registered User
    Join Date
    11-07-2011
    Location
    Germany
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Copy marked rows from other sheets to current sheet

    I'm trying to integrate this function into the main workbook now, and I'm running into problems with defined objects (I think).

    This is the code as it stands:
    Please Login or Register  to view this content.
    I combined what I learned in this thread so far with some code that has been working throughout the rest of the workbook quite well (checking through the tabs for names it recognizes, copying the whole worksheet and pasting into the current sheet below the existing data). However, now I want it to sort for "x" before copying and pasting into the current sheet... ideas?
    Attached Files Attached Files

  13. #13
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Copy marked rows to new sheet

    The error you get is because it s

    xlUp, not x1up

  14. #14
    Registered User
    Join Date
    11-07-2011
    Location
    Germany
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Copy marked rows to new sheet

    ah, silly mistake.... i guess that's what happens when you're just learning as you go along!

+ 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