+ Reply to Thread
Results 1 to 19 of 19

Copy entire row to new sheet

  1. #1
    Registered User
    Join Date
    11-12-2017
    Location
    Stafford, England
    MS-Off Ver
    365
    Posts
    184

    Copy entire row to new sheet

    Hi,

    I know this is probably covered in a thread somewhere but I have searched through lots of posts but amending the VBA is confusing me.

    I am looking to copy the entire row to a new sheet where the reason code in column I matches a certain number.
    Reason code 1 copy to sheet "1", reason code 4 copy to sheet "4", reason code 7 copy to sheet "7"... etc
    I assume this is best done through VBA and not a formula or conditional formatting.
    I would like sheet "1" to stay as it is just copy data with no formatting to respective sheets.

    Thanks
    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: Copy entire row to new sheet

    This can of course be done with a Data Advanced Filter, either manually or using VBA, however probably the simplest way is tio use a Pivot Table and double click a value.

    In the attached I've added a Pivot Table that shows the adjustment reason and the Cost Price Value. It's not important which of the fields you put in the values area.

    When you double click one of the Pivot Table rows a new sheet will be added automatically.
    Attached Files Attached Files
    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
    Valued Forum Contributor
    Join Date
    11-28-2015
    Location
    indo
    MS-Off Ver
    2016 64 bitt
    Posts
    1,260

    Re: Copy entire row to new sheet

    Sorri not open workbook
    'eg your sheet data in sheet1 and data in col i have data 1,2,3 etc
    Please Login or Register  to view this content.
    Last edited by daboho; 11-24-2018 at 01:45 PM.

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,210

    Re: Copy entire row to new sheet

    Another option...
    Please Login or Register  to view this content.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  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: Copy entire row to new sheet

    I suppose the obvious question is what is the essence of the task? is it to split one database down into its subsets on completely different sheets (and if so why, how do you use those?), or is it to see the records for any particular reason code - and if so why not just use an autofilter?

  6. #6
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Copy entire row to new sheet

    Hello ~TaC~,

    You may want to consider this option as well.

    Please Login or Register  to view this content.

    Regards
    Attached Files Attached Files
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  7. #7
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,210

    Re: Copy entire row to new sheet

    My understanding...Is that OP wants all the rows that contain....In Column I
    "1" to be copied to sheets("1")
    "4" to be copied to sheets("4")
    "7" to be copied to sheets("7")
    ...and so on...
    Last edited by sintek; 11-24-2018 at 01:42 PM.

  8. #8
    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: Copy entire row to new sheet

    Quote Originally Posted by sintek View Post
    My understanding...Is that OP wants all the rows that contain....In Column I
    "
    ...and so on...

    I agree, that was clearly stated by the OP. I'm merely asking the question why, since the optimum solution will depend on what the workbook is actually being used for, i.e. the end goal.

    I've come across too many occasions where someone has a need to know something and has found a way of presenting it which may not be the most efficient way of obtaining what they really want. The mistake often made is to set off on a course of action without realising there are other ways. Indeed one of our rules hints at this where it talks about not offering a suggested solution.

    In this case I'm suggesting that if all that's needed is knowledge of which part of a data set meets a particular criteria, then unless there's some vital need for breaking down a large database into lots of subsets then an Autofilter seems the most effcient and direct.

    Even if the user subsequently wants to create a new workbook containing the filtered data, (and we don't know how all these additional sheets are used) then a single template sheet could be used, populated at runtime by a macro and then copied to a new workbook.

  9. #9
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,210

    Re: Copy entire row to new sheet

    Very true Richard...Forgot to add @ My mater Winon

  10. #10
    Registered User
    Join Date
    11-12-2017
    Location
    Stafford, England
    MS-Off Ver
    365
    Posts
    184

    Re: Copy entire row to new sheet

    Being somewhat of a novice I can honestly say I wasn't aware of the autofilter option, but this definitely sounds like what I need.

    I'm not looking to do anything complex, I just want to separate the data to make it easier to read. Having the conditional formatting highlight certain rows on Sheet 1 is useful to see any discrepancies between same products. However, separating the data to different sheets based on reason code (column I) is required to filter how stock is lost/gained. Reason codes represent how stock is lost/gained, i.e. theft, delivery discrepancies, inaccurate counts, etc.

  11. #11
    Valued Forum Contributor
    Join Date
    06-29-2014
    Location
    Australia
    MS-Off Ver
    MSO 365
    Posts
    1,098

    Re: Copy entire row to new sheet

    Hello TaC,

    Based on what you have said in your last post, automating the autofilter with the following code should do the task for you:-


    Please Login or Register  to view this content.
    The code will transfer the relevant rows of data to the relevant individual sheets. Assuming that you want all data to remain in the main ("closed") sheet, the code will clear each of the individual destination sheets each time that the code is run. This basically is refreshing each sheet.

    I've attached your sample workbook with the code implemented. Click on the "RUN" button to see it run.

    I hope that this helps.

    Cheerio,
    vcoolio.
    Attached Files Attached Files

  12. #12
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,210

    Re: Copy entire row to new sheet

    @ vcoolio

    Would work...Only if the numbers in the array are the only ones present in Column I
    Please Login or Register  to view this content.
    @ TaC

    Code provided in Post 4 is one option of a working solution...

  13. #13
    Valued Forum Contributor
    Join Date
    06-29-2014
    Location
    Australia
    MS-Off Ver
    MSO 365
    Posts
    1,098

    Re: Copy entire row to new sheet

    @Sintek:

    True. However there is no indication in any of the OP's posts (or in the sample workbook) that there are any other worksheets. So, there are two further options should there be more worksheets:-

    1) Just add to the array ( a few seconds work)

    or

    2) Place Column I into an array; e.g.

    Please Login or Register  to view this content.
    Cheerio,
    vcoolio.

  14. #14
    Registered User
    Join Date
    11-12-2017
    Location
    Stafford, England
    MS-Off Ver
    365
    Posts
    184

    Re: Copy entire row to new sheet

    Hey vcoolio,

    Copies all the data as I require, I can easily add more sheets if and as required so thats not a problem.

    Just need to sort out formatting issues and it'll be good to go, but thats a whole new thread

    Thanks.

  15. #15
    Valued Forum Contributor
    Join Date
    06-29-2014
    Location
    Australia
    MS-Off Ver
    MSO 365
    Posts
    1,098

    Re: Copy entire row to new sheet

    Hello TaC,

    You're welcome. Glad to have been able to help.

    Just for your future reference, keep the following code up your sleeve:-


    Please Login or Register  to view this content.
    Its basically the same code with just a couple of modifications (in red font). It places Column I into an array which means that if you do add any more sheets in future, the code will deal with them also without you having to worry about amending the code.

    Cheerio,
    vcoolio.

  16. #16
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,210

    Re: Copy entire row to new sheet

    @ vcoolio

    Just a heads up...Your code is filtering multiple duplicates...I suggest you store the unique values in Col I into your array prior to loop...

  17. #17
    Valued Forum Contributor
    Join Date
    06-29-2014
    Location
    Australia
    MS-Off Ver
    MSO 365
    Posts
    1,098

    Re: Copy entire row to new sheet

    @Sintek:

    Yes. I could use Advanced Filter to store the unique values temporarily in another column and assign these to an array.

    However, it works smoothly enough as it is and the OP is happy enough. So that's something for another time.

    For now, I have to go and check the chicken in the oven!

    Cheerio,
    vcoolio.

  18. #18
    Registered User
    Join Date
    11-12-2017
    Location
    Stafford, England
    MS-Off Ver
    365
    Posts
    184

    Re: Copy entire row to new sheet

    As I said, works for what I need and answers my original query.

    There is fine tuning to do as with anything and this make change needs, but it solved the issues of copying to another sheet so I'll mark as Solved!

    Thanks all

  19. #19
    Valued Forum Contributor
    Join Date
    06-29-2014
    Location
    Australia
    MS-Off Ver
    MSO 365
    Posts
    1,098

    Re: Copy entire row to new sheet

    You're welcome TaC and thanks for the rep.

+ 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] EXCEL Find variable data from one sheet and copy entire row to another sheet
    By Crawfy in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-27-2017, 06:21 AM
  2. Replies: 6
    Last Post: 11-13-2015, 07:36 AM
  3. VBA Code to Copy entire sheet and paste in another sheet
    By molly13 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-28-2015, 11:45 AM
  4. Replies: 0
    Last Post: 06-26-2014, 11:31 AM
  5. [SOLVED] Match Value in Sheet 1 with Sheet 2, copy entire row from sheet 1 to new sheet
    By lzyshaman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-01-2013, 07:48 AM
  6. Copy Entire Sheet
    By Linda in forum Excel General
    Replies: 1
    Last Post: 06-11-2006, 06:10 PM
  7. [SOLVED] [SOLVED] Copy the entire sheet to overlay existing sheet?
    By LurfysMa in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 08-29-2005, 03:05 PM

Tags for this Thread

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