+ Reply to Thread
Results 1 to 20 of 20

Copy and append an array of cells based on a separate date table

  1. #1
    Forum Contributor
    Join Date
    09-29-2011
    Location
    Cape Town
    MS-Off Ver
    Excel 2010
    Posts
    107

    Copy and append an array of cells based on a separate date table

    Hi there,

    I have a sheet that contains products (column B) and a list of ingredients that go into these products (column A) - see attached

    I have roughly 50 products and I need to replicate these according to whether a separate date table is populated i.e. If the date table has Jan '17 and Feb '17 populated, I need the product and the corresponding ingredients to be duplicated twice (one for Jan and then again for Feb). If I then add Mar '17 to the Date table, then the same product and corresponding ingredients need to be appended below the Jan and Feb entries.

    I have attached an excel doc with a simple example. The problem I am having is that I have 50 products and need to replicate these 24 times each (which I can currently do manually, but going forward I'm looking to automate this process by having a macro only populate what is in the date dimension table).

    In the excel provided I have selected 2 products and have manually populated Jan and Feb '17. Ideally the macro would look at the Date tab and then append a further 22 iterations of each.

    Please keep in mind that I do have a master product list and the ingredients do not change.

    Thanks a million!
    Attached Files Attached Files
    Last edited by concatch; 01-09-2018 at 01:13 PM.

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

    Re: Copy and append an array of cells based on a separate date table

    Hi concatch

    Your actual requirement escapes me...Can you perhaps explain in more detail...
    Where do the products/ingredients come from?
    No sheet in attached housing this...
    If the date table has Jan '17 and Feb '17 populated
    Populated how?
    Last edited by sintek; 12-30-2017 at 01:19 PM.
    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!!!

  3. #3
    Forum Contributor
    Join Date
    09-29-2011
    Location
    Cape Town
    MS-Off Ver
    Excel 2010
    Posts
    107

    Re: Copy and append an array of cells based on a separate date table

    I Have updated the test file - please have a look, hopefully the requirement is more clear... Thanks
    Attached Files Attached Files

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

    Re: Copy and append an array of cells based on a separate date table

    I am very certain that someone else will offer a more efficient code...Mind is foggy right now...Will have a look at improving it tomorrow...
    Please Login or Register  to view this content.
    Last edited by sintek; 12-30-2017 at 05:36 PM. Reason: Updated code...

  5. #5
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Copy and append an array of cells based on a separate date table

    Give this a try

    Please Login or Register  to view this content.
    Last edited by mike7952; 12-30-2017 at 06:47 PM.

  6. #6
    Forum Contributor
    Join Date
    09-29-2011
    Location
    Cape Town
    MS-Off Ver
    Excel 2010
    Posts
    107

    Re: Copy and append an array of cells based on a separate date table

    Busy testing now - so far seems to be doing exactly what I'm looking for. Will provide an update in the morning. Thanks a million!

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

    Re: Copy and append an array of cells based on a separate date table

    After I put my head down last night I realized that I had a extra unnecessary loop....
    Please Login or Register  to view this content.
    Last edited by sintek; 12-31-2017 at 01:24 AM.

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

    Re: Copy and append an array of cells based on a separate date table

    ...Deleted...
    Last edited by sintek; 12-31-2017 at 01:23 AM.

  9. #9
    Forum Contributor
    Join Date
    09-29-2011
    Location
    Cape Town
    MS-Off Ver
    Excel 2010
    Posts
    107

    Re: Copy and append an array of cells based on a separate date table

    Hi,

    I've tried for a while to adjust your code as the actual column format I'm working with has 4 columns in this format...Sorry I know I should have mentioned this sooner. Preliminary testing is going well though. Will provide feedback later today. Thanks for your efforts.

    Serial No. |Raw Material | Product | Value
    1 RW: Baking Powder SWEET: KOURABIEDES 5

  10. #10
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Copy and append an array of cells based on a separate date table

    Can you upload a file with the exact data structure of your workbook?
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  11. #11
    Forum Contributor
    Join Date
    09-29-2011
    Location
    Cape Town
    MS-Off Ver
    Excel 2010
    Posts
    107

    Re: Copy and append an array of cells based on a separate date table

    Hi mike7952, apologies for the delayed response, I've created a new test file which contains the exact format and outputs.

    'Master List' will be unique list of products with their corresponding raw materials

    'Date' will run to Dec 2018 - I will likely update this in 2019 then rerun the macro

    'Product Lookup' - I have selected 3 products and manually displayed the outputs and the columns

    Thanks again for your assistance, much appreciated!
    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,221

    Re: Copy and append an array of cells based on a separate date table

    My amended code...
    Please Login or Register  to view this content.

  13. #13
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Copy and append an array of cells based on a separate date table

    concatch,
    See if this is how you wanted.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  14. #14
    Forum Contributor
    Join Date
    09-29-2011
    Location
    Cape Town
    MS-Off Ver
    Excel 2010
    Posts
    107

    Re: Copy and append an array of cells based on a separate date table

    Hi sintek - I'm getting an error on the line Set PrGrp = CreateObject("System.Collections.ArrayList")

    Error: Run-time error '-2146232576 (801131700)

    I have tried to google but with no success in resolving the issue. Any suggestions?

    Thanks!

  15. #15
    Forum Contributor
    Join Date
    09-29-2011
    Location
    Cape Town
    MS-Off Ver
    Excel 2010
    Posts
    107

    Re: Copy and append an array of cells based on a separate date table

    Hi jindon,

    Thanks for your solution -

    I receive the following error:

    Run-time error '-2147217900 (80040e14)

    Syntax error (missing operator) in query expression 'Product' = 'SPECIALITY: FALAFEL (4's - COOKED)".

    I suspect it has something to do with this specific Product having certain characters that are not catered for in your code...not quite sure how to get around this without changing the source data... Any thoughts?

    Thanks a million!

  16. #16
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Copy and append an array of cells based on a separate date table

    Try this one then...
    Please Login or Register  to view this content.
    Last edited by jindon; 01-08-2018 at 06:13 AM.

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

    Re: Copy and append an array of cells based on a separate date table

    No errors in sample...

    Perhaps this is reason???
    https://social.msdn.microsoft.com/Fo...forum=exceldev
    Attached Files Attached Files
    Last edited by sintek; 01-08-2018 at 06:40 AM.

  18. #18
    Forum Contributor
    Join Date
    09-29-2011
    Location
    Cape Town
    MS-Off Ver
    Excel 2010
    Posts
    107

    Re: Copy and append an array of cells based on a separate date table

    It worked - was an update issue. Thanks again for your help over the past few days, much appreciated!

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

    Re: Copy and append an array of cells based on a separate date table

    Glad you got it sorted...Thanks for rep +

  20. #20
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Copy and append an array of cells based on a separate date table

    You are welcome and thanks for the rep.
    Yes, Dictionary should work on Wnidows regardless of the version.

+ 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] On cell change copy and append to bottom of table
    By wacky_diva in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-13-2017, 12:36 AM
  2. [SOLVED] Copy All But the First Row of a Table Databody and Append to the End of Another Table
    By TheScott in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-21-2015, 02:43 AM
  3. [SOLVED] Excel2010 IF Formula to return value based on a separate date and two separate text values
    By jakecutler in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-12-2015, 03:24 AM
  4. Copy cells append to table
    By Dave H in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-28-2014, 09:54 AM
  5. Replies: 0
    Last Post: 02-06-2013, 08:25 PM
  6. Replies: 3
    Last Post: 02-05-2008, 11:13 AM
  7. Append data from a column to separate table array
    By miss_q in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-12-2005, 07:01 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