+ Reply to Thread
Results 1 to 25 of 25

Splitting Datasets to new TABs by column title MACRO

  1. #1
    Forum Contributor
    Join Date
    12-01-2010
    Location
    Southampton, England
    MS-Off Ver
    Excel 2007
    Posts
    303

    Splitting Datasets to new TABs by column title MACRO

    Hi guys many thanks for taking the time to look at my problem.

    I have provided an example here to try and clarify what the problem in question is and what result should be achieved. Essentially I need a macro which can refer to column PB and go down it to find any new Schools, upon finding a new school it would creat a Tab named after that school (as shown by example tab) Upon creating the sheets the macro would proceed to copy each Matching array (All the way accross to the right of the spreadsheet the data extends as far as column "BAN", also might be worth noting this isnt continuous so their may be some blank columns amongst that) to the new tab. It would start the first array in row 16 and then each subsiquent matching array would be beneath these with one row to seperate them. My real spreadsheet is both confidential in nature, as well as far to large to upload as an example. Instead i have made the layout of this sheet the same as my 'real' sheet. One other thing to conisder is that the real sheet contains over 30,000 of these arrays. (I am aware some coding is less efficient than others.)

    Thanks again for taking the time to look at this problem!

    Cheers Alan
    Attached Files Attached Files

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Splitting Datasets to new TABs by column title MACRO

    If you didn't have 30,000 "groups" we could employ some cool "special cells > areas" techniques, but as it is, this should work. Assuming there are no completely empty columns within each group, this seems to work:

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 07-08-2012 at 09:13 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Contributor
    Join Date
    12-01-2010
    Location
    Southampton, England
    MS-Off Ver
    Excel 2007
    Posts
    303

    Re: Splitting Datasets to new TABs by column title MACRO

    Thanks so much for the macro JBC, its very good and does nearly all that is required. There appears to be only two small errors with it (which i do not know how to fix.) Firstly in sheet1 column A there is Title1 and Title2. These are specific to each array (not always the same) so the macro needs to import them also to the new sheet. The second problem i have with it is that it has two blank rows between each array. I need the layout to be one blank row, (new row) title1, (new row) title2, then the rest of the array. I hope that makes sense? I tried to demonstrate this in the example sheet provided.

    I cant thank you enough for the help, this code will be of great use to me!

    Alan

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Splitting Datasets to new TABs by column title MACRO

    My test of the macro above DOES include the Title1 and Title2 in each array copied.

    I highlighted in red in the code above the part that offsets each set of data. I had a 3 in there and changed it to a 2, which should leave a single blank row between sets of data.

  5. #5
    Forum Contributor
    Join Date
    12-01-2010
    Location
    Southampton, England
    MS-Off Ver
    Excel 2007
    Posts
    303

    Re: Splitting Datasets to new TABs by column title MACRO

    Hi JB, thanks again for the prompt reply. However in my version it still doesn't import title 1 and title 2. Not sure what i could be doing wrong. It would also be good if the macro put the first text in row 16. I have a attached another example sheet with your macro in. The example shows what your macro returns and also an example of what is needing to be achieved, i hope this makes sense.

    All the best,

    Many thanks

    Alan
    Attached Files Attached Files
    Last edited by JBeaucaire; 07-09-2012 at 10:10 AM. Reason: corrected my initials

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Splitting Datasets to new TABs by column title MACRO

    I only made one caveat:

    Quote Originally Posted by JBeaucaire View Post
    ...Assuming there are no completely empty columns within each group, this seems to work...
    Why the empty columns? No empty columns makes EVERYTHING simpler, data is easier to manipulate and read and process.... sigh.

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Splitting Datasets to new TABs by column title MACRO

    Ok, add this line of code, rather than rewriting the whole thing, I'm making at least one of those blank cells in each group "not blank" so the code works as designed.

    Please Login or Register  to view this content.

    Reasoning: By having at least one cell in each column throughout a group have a value, it creates a "connected region". With that, the CurrentRegion reference in the copy command can find all the connected cells in a group, including your titles which stick out above.

  8. #8
    Forum Contributor
    Join Date
    12-01-2010
    Location
    Southampton, England
    MS-Off Ver
    Excel 2007
    Posts
    303

    Re: Splitting Datasets to new TABs by column title MACRO

    Reason: corrected my initials
    Lol.

    Cheers for code, ill give it a whirl.

    Alan

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Splitting Datasets to new TABs by column title MACRO

    All good? If that takes care of your need, please select Thread Tools from menu above and set this topic to SOLVED.

  10. #10
    Forum Contributor
    Join Date
    12-01-2010
    Location
    Southampton, England
    MS-Off Ver
    Excel 2007
    Posts
    303

    Re: Splitting Datasets to new TABs by column title MACRO

    Hello JB,

    The method used by this macro errors out after completion of tabs worth of data, (i.e. it splits up one tab, dies on the next) furthermore it creates problems for many of the other macros I use, as a result of creating aforementioned "connected regions." Is there anything that can be done with that macro, or does this need approaching differently?

    Many thanks

    Alan

  11. #11
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Splitting Datasets to new TABs by column title MACRO

    The macro I gave doesn't have any code included for processing multiple tabs of raw data, so I'd have to see what you added before I can offer a guess as to why it "dies". On a single sheet it works, which is all I wrote in, and it sounds like it completes that?

    I can't really comment on your other macros.

  12. #12
    Forum Contributor
    Join Date
    12-01-2010
    Location
    Southampton, England
    MS-Off Ver
    Excel 2007
    Posts
    303

    Re: Splitting Datasets to new TABs by column title MACRO

    Hello JB,

    Apologies for the ambiguity, it fails upon production of the second tab. There is not a second tab to be processed. It is failing on the first sheet of data. This macro is one of hundreds in my current project. Is there a way of achieving the same result without the
    Please Login or Register  to view this content.
    This created far more problems than it solved with regards to the data analysis I am trying to undertake. I appreciate that it is difficult to understand without access to the spreadsheet.

    Thanks again

    Alan

  13. #13
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Splitting Datasets to new TABs by column title MACRO

    Maybe by trying to remember the cells where the " " was added, we can remove it later.
    Please Login or Register  to view this content.

  14. #14
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Splitting Datasets to new TABs by column title MACRO

    I received a PM from OP to weigh in. I think the macro provided by JB is really quite good, so I just made some adjustments to it.
    I expanded the example workbook to have 34728 arrays (groups of data). This macro completed successfully and put each data group to its intended destination.
    With that much data, this macro took 723.51953125 seconds (about 12 minutes, 4 seconds) to complete.

    Here's what I came up with:
    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  15. #15
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Splitting Datasets to new TABs by column title MACRO

    (chuckle) Tiger, I think a better introduction might be: "Here's a macro you can try".

    Yours is certainly not an adjustment to mine, right? That made me chuckle out loud, thanks for that. (thumbs up for a positive spin)

  16. #16
    Forum Contributor
    Join Date
    12-01-2010
    Location
    Southampton, England
    MS-Off Ver
    Excel 2007
    Posts
    303

    Re: Splitting Datasets to new TABs by column title MACRO

    Thanks guys, I simply wish to be able to code like you guys one day! Top notch!

    Many thanks

    Alan

  17. #17
    Forum Contributor
    Join Date
    12-01-2010
    Location
    Southampton, England
    MS-Off Ver
    Excel 2007
    Posts
    303

    Re: Splitting Datasets to new TABs by column title MACRO

    In typical Alan style, I have already run into an issue with the way in which I implement this macro.

    Essentially I want to run it on two different sheets in the same workbook we shall call these sheet X and sheet Y. The two different sheets have overlapping "schools", however the sheets produced are needing to be kept separately. Is it possible to import the name of the originating sheet prior to school name. I.e we could produce a sheet called "sheet X School 1" and similarly there could be a sheet produced called "sheet y School 1" when the code was run on sheet y.

    I am aware this would present a further problem when we come to re run the macro on Sheet x, after an update (more data added) because now the macro would need to recognize "sheet X School 1" rather than the prior "school 1"

    I hope this makes sense?

    All the best

    Alan

  18. #18
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Splitting Datasets to new TABs by column title MACRO

    Alan,

    Updated code. Let me know if you'd rather have the code run on both SheetX and SheetY at the same time:
    Please Login or Register  to view this content.

  19. #19
    Forum Contributor
    Join Date
    12-01-2010
    Location
    Southampton, England
    MS-Off Ver
    Excel 2007
    Posts
    303

    Re: Splitting Datasets to new TABs by column title MACRO

    Brilliant Tiger,

    Running on active sheet is fine. Many thanks. The idea behind the macro is obviously to split of a large chunk of the arrays for data analysis. One problem I have is that the amount of data I am receiving is always growing, this means that when I come to need to update these produced sheets I would currently need to clear the entire sheet. And re run the macro. However since I analyse all of this data to the right of the data, is there a way of making this macro only import new data to these produced sheets?? One way I can think of doing it would be to reference column BW lastrow in each of the sheets will contain the date of the last import.

    Shall I post a new thread for this task?

    Essentially it is the same splitting mechanism, but not splitting the entire sheet each time after they have been created.

    All the best

    Alan

  20. #20
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Splitting Datasets to new TABs by column title MACRO

    I think the new request is still closely related enough that it doesn't warrant a new thread. I do need some information before I can make the adjustment though.

    The macro would need to know what data has already been imported in order to prevent itself from importing it again. I know you stated that the last row in column BW will contain the date of the last import, but what are we comparing that against? Is there a date the data was added to sheetX or sheetY somewhere next to each dataset?

  21. #21
    Forum Contributor
    Join Date
    12-01-2010
    Location
    Southampton, England
    MS-Off Ver
    Excel 2007
    Posts
    303

    Re: Splitting Datasets to new TABs by column title MACRO

    Hi tiger,
    In answer to your last question no there isnt, however the most recent data in these sheets (non split sheets) will also be towards the bottom of the page, and also contains the date in column BW, my thoughts were that the macro could reference the date at the bottom of column BW in the new created sheets to know which is the last date imported and thus find the start of the new data in the non split sheets, since their dates will be chronologically after said referenced date??

    Does this makes sense? Is this plausible?

    Many thanks

    Alan
    Last edited by Cutter; 07-31-2012 at 04:47 PM. Reason: Removed whole post quote

  22. #22
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Splitting Datasets to new TABs by column title MACRO

    If there isn't anything to compare it against, then we'll have to add something to compare it against. Here's the macro updated to add the date and time of import to the first data row of each dataset in column BV. If BV isn't a good column to use, just change the column where indicated. The timestamp column should be blank in both the data sheet and the destination sheet. Then, whenever the macro runs, it will check each dataset's timestamp. If that timestamp exists in the destination sheet, it will ignore that dataset and go on to the next one. This could be improved further if the SheetX and SheetY are guaranteed to never have inserted rows or have the data rearranged. Then the macro could just start at the dataset below the last timestamped data. Let me know if that is the case.
    Please Login or Register  to view this content.

  23. #23
    Forum Contributor
    Join Date
    12-01-2010
    Location
    Southampton, England
    MS-Off Ver
    Excel 2007
    Posts
    303

    Re: Splitting Datasets to new TABs by column title MACRO

    Thanks again for the macro tiger, if it is a simple change is it possible to have a set cell as the reference cell and simply refer to this ? I have uploaded an updated example with the dates in. For instance we could designate a cell to be overwritten each time the macro was run. This cell would then be compared to the date in column BW? Designating a whole column seems a little inefficient considering the size of our sheet and the number of arrays.

    Many thanks

    Alan
    Attached Files Attached Files

  24. #24
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Splitting Datasets to new TABs by column title MACRO

    Alan,

    Something like this? The variable rngDate refers to cell BW1 on wsData. Change as desired.
    Please Login or Register  to view this content.

  25. #25
    Forum Contributor
    Join Date
    12-01-2010
    Location
    Southampton, England
    MS-Off Ver
    Excel 2007
    Posts
    303

    Re: Splitting Datasets to new TABs by column title MACRO

    Perfect (Until I find a reason why its not) Thanks as always Tiger!

+ 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