+ Reply to Thread
Results 1 to 22 of 22

Copying Rows and Separating Tables

  1. #1
    Registered User
    Join Date
    01-08-2014
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    15

    Copying Rows and Separating Tables

    Hi,

    I have an excel sheet that I'm trying to format. Basically, the excel book contains sheets (with the months), and each sheet contains a list of clients, their package, their status, date assigned, and date updated.

    I've made another sheet (Sheet2) that fetches everything and consolidating it to one sheet. Sheet 2 also cleans up the data to display only the items that are 'completed'.

    The issue I'm having now is in splitting the list (assuming it has been cleaned up to show only the 'completed' items. I would need to split the list first by the date they were updated, and then if they were assigned the same date or not. In short:
    --Get all items with date updated = Month1
    ----If date assigned = Month 1: List items under table 1
    ----If date assigned < Month 1: List items under table 2

    I've used macro on the excel (and I'm not sure it's efficient enough. I'm not proficient with VB, so...). I'm not sure if it will work on Mac.

    Any help would be appreciated. Thanks!
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Copying Rows and Separating Tables

    From what I can see, looking at and running your code, it's already doing nearly everything you want copying month 1 data to Sheet3, but you need it to continue copying the remaining data to a sheet4. Am I correct? If so, this should do it. You'll need to add Sheet4 before running.
    Please Login or Register  to view this content.
    It also appears that you derived most of your other code, like CopyAll, using the Macro recorder, then doing a little tweaking. That's a good way to start, and to find out how to do something, but is generally inefficient and inflexible. Note how your code repeats itself for each month. That's redundant, and makes future adjustments difficult. Assuming that your final product will end up with more than the 4 months in your sample sheet, you will probably want to have a generic subroutine for handling a month, then loop through your sheets and call the subroutine for each. If you need suggestions on how to proceed, let me know.
    Acts 4:12
    Salvation is found in no one else, for there is no other name under heaven given to mankind by which we must be saved.

  3. #3
    Registered User
    Join Date
    01-08-2014
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    15

    Re: Copying Rows and Separating Tables

    Thanks for the help! Yes, actually the excel file would be larger (would contain more sheets, corresponding to months for the year)

    What I was planning to do with sheet 3 was to display a split list of everything from sheet 2. Since sheet 2 contains the refined data from all the other sheets, sheet 3 would be the final product... so everything would be pasted in sheet 3.

    I was thinking of having it this way, if possible:
    (Sheet3):
    (Cell A1): January
    (Cell B1): Same Month
    (Row 3): <the headers>
    (succeeding rows): all items closed in january and assigned in january
    (1 blank row after the list)
    (Column 1, 1 row after the above): Previous Month
    (succeeding rows): all items closed in january and assigned before january
    (2 blank rows after the list)
    (Column 1, 1 row after the above): February
    (1 row below the previous): Same Month
    (1 row below the previous): <the headers>
    (succeeding rows): all items closed in february and assigned in february
    (1 blank row after the list)
    ...
    until December.

    So everything would be consolidated to Sheet 3...

    Also, one question... Is it possible to put in the buttons on sheet 3, but would still retain the same functionality (still process everything on sheet 2), and will they still operate even if I set sheet 2 as hidden?

  4. #4
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Copying Rows and Separating Tables

    Is the data on Sheet2 even needed, other than to build Sheet3? In other words, once Sheet3 is built, will you still need Sheet2? If not, I'd probably just build sheet3 directly from the monthly sheets, and just do it with one step rather than all the buttons, unless you need to see the data after each step.

  5. #5
    Registered User
    Join Date
    01-08-2014
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    15

    Re: Copying Rows and Separating Tables

    I initially used sheet 2 for checking if I got every step correct... so if we could have it in one go, then that's better. :-)

  6. #6
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Copying Rows and Separating Tables

    I ended up starting from scratch, but the attachment should get you close to what you want. Just click the Process Months button. Have fun!

    sample.xlsm
    Last edited by natefarm; 01-17-2014 at 12:20 PM. Reason: Updated to handle multiple tables per sheet as requested

  7. #7
    Registered User
    Join Date
    01-08-2014
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    15

    Re: Copying Rows and Separating Tables

    Thanks so much~! I'll check this when I get home (I'm away at the moment) :-)

    Edit: I checked over the attachment. I'm sorry if I wasn't clear. This is similar to what I'm trying to accomplish, but the split happens on the date updated, not the date assigned.

    So, it splits the table by month (Date Updated), then check if it's under the same Month (Date Updated = Date Assigned), or if it's from previous month (Date Updated > Date Assigned). Also, we need to include only the items that are "Completed" (Status = "Completed") so it might be a little tricky... I dunno. XD

    Thanks for the file though. I'll go study it more and see if I could tweak it a little XD
    Last edited by shiningriver; 01-11-2014 at 03:41 AM.

  8. #8
    Registered User
    Join Date
    01-08-2014
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    15

    Re: Copying Rows and Separating Tables

    Hi natefarm,

    Is it possible to include comments on the macro you've made? I'm having a hard time deciphering it. :-)

  9. #9
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Copying Rows and Separating Tables

    I had fixed a problem where it wasn't excluding uncompleted records, but somehow those changes hadn't been updated. Sorry if that caused confusion.
    It's been fixed now, and I have added comments as well. It also might be helpful to learn to use the debugger, if you don't know how. Restore your code window down to where you can see the code, with your full-screen workbook behind it. Then step through the code line-by-line (press f8) so you can see what each step does. You can put debug stops later in the code to skip some of the tedious loops (click in the band down the left side to add or remove a stop, then press f5 to run the code until it hits that line). Also, if you don't know what a certain property or method means, click it and hit f1 for help.

  10. #10
    Registered User
    Join Date
    01-08-2014
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    15

    Re: Copying Rows and Separating Tables

    This is where I'm lost now. I'm trying to make changes on the macro so that the one that is sorted is the "Date Updated" instead of the "Date Assigned"... I'm not sure where on the macro it is T___T

  11. #11
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Copying Rows and Separating Tables

    I see. I guess I was picturing it backwards from what you wanted. I revised the sample attachment above to use the other date. It required not only sorting differently, but changing it to use column 7 to determine the breakpoints instead of column 1. See if I got it right this time. Thanks.

  12. #12
    Registered User
    Join Date
    01-08-2014
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    15

    Re: Copying Rows and Separating Tables

    Yes, this works perfectly! Thank you so much for your help. :-)

  13. #13
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Copying Rows and Separating Tables

    Glad to hear it. Remember to mark the thread as Solved, and reputation points are always appreciated by whomever helped you

  14. #14
    Registered User
    Join Date
    01-08-2014
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    15

    Re: Copying Rows and Separating Tables

    Hi, quick question. Would it be possible to append this if for example, each sheet contains two tables (somewhat like an expansion of the first file, but instead of 1 table under each sheet, each sheet would contain 2 tables separated by 1 column. Each table has the same headers, but different contents. Records for "branch #1" and "branch #2")?

  15. #15
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Copying Rows and Separating Tables

    I have modified the sample attachment to pull in data from as many tables as it finds on each sheet. It doesn't matter which row or column each table starts in, as long as the "#" is found in the left-most cell of the heading. The sample has examples and is ready to run.

  16. #16
    Registered User
    Join Date
    01-08-2014
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    15

    Re: Copying Rows and Separating Tables

    Thanks! I was thinking if it was possible to process them separately? I mean, as an alternate example? Since the sheets would mostly contain only a max of 2 tables per sheet, Is it possible to process table 1 from each sheet, then table 2 from each sheet?

  17. #17
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Copying Rows and Separating Tables

    You mean onto 2 different output sheets?

  18. #18
    Registered User
    Join Date
    01-08-2014
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    15

    Re: Copying Rows and Separating Tables

    Sorry, I meant another version of that sample.xlm. Another version, where the processing of the tables are separated (table 1 first, then table 2).

    On a side note, I tried the code on a new sheet, which all contained data from January 2014 and previous months. It seems to recognize the items completed and assigned in january as 'previous months' instead of 'same month'.

  19. #19
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Copying Rows and Separating Tables

    Since the code identifies the tables by the #, you could avert the processing of one of them by deleting the # from that table.

    The Jan 2014 issue is because you have 2013 hard-coded in your your column J formula. The formula should probably be simplified anyway. I don't see the purpose of the If.

  20. #20
    Registered User
    Join Date
    01-08-2014
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    15

    Re: Copying Rows and Separating Tables

    Sorry for the late reply... been busy lately hehehe.
    I tried the function without the J column again, and it seems that it still mixes the previous and the same month... I've attached a screenshot (blurred data sections for confidentiality hehehe)
    sample.jpg

  21. #21
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Copying Rows and Separating Tables

    You didn't show what change you made to column J, but I don't know why this much simpler formula wouldn't work:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  22. #22
    Registered User
    Join Date
    01-08-2014
    Location
    London, England
    MS-Off Ver
    Excel 2013
    Posts
    15

    Re: Copying Rows and Separating Tables

    Ah, I just removed column J entirely.

+ 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. Separating data in a row into new rows - can it be done?
    By MortenPetterson in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-28-2012, 10:18 AM
  2. Copying pivot tables as data tables with formatting
    By wolis in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-17-2012, 12:57 AM
  3. [SOLVED] Copying and Separating out delimited fields
    By ahunter488 in forum Excel General
    Replies: 6
    Last Post: 06-18-2012, 11:18 AM
  4. Copying Rows from Multiple Tables into One
    By vlbridge in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-03-2011, 05:43 PM
  5. Excel 2007 : Separating Data from Rows to a New Row
    By teh_siggy0731 in forum Excel General
    Replies: 1
    Last Post: 05-17-2010, 03:23 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