+ Reply to Thread
Results 1 to 16 of 16

Macro to consolidate entries from days to weeks

  1. #1
    Registered User
    Join Date
    10-15-2012
    Location
    Oakland, CA
    MS-Off Ver
    Excel 2010
    Posts
    43

    Macro to consolidate entries from days to weeks

    Hi All,

    I'm looking for a way to consolidate entries in the "Import" tab which have data at the daily level, into weekly level entries (basically summing the data if it has the same Number, Day and Foods). I have a Calendar worksheet that shows what the new week entry should be. After it consolidates the entries, I need it to adjust those numbers using the Adjustment table, so all "Tomato" values are increased by 3.2% (e.g final value would then be 1.032 times its original value).

    Can someone assist me with this? I've attached example data.

    Thank you greatly!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Macro to consolidate entries from days to weeks

    I adjusted your file a bit.

    In calendar it automatically assigns the first day of the week in column B

    It also populates the output tab when you run the macro included

    I did not adjusted since it was not clear where to place the result (aside to the right or in the same cell)

    Cheers,
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    10-15-2012
    Location
    Oakland, CA
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Macro to consolidate entries from days to weeks

    Hi rcm,

    Thanks for the help! Is there any way to do this and delete the helper column after? (VBA newbie here)

    It looks good though, thanks again!

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

    Re: Macro to consolidate entries from days to weeks

    The result in attached slightly differ from your result, see figure in red.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    10-15-2012
    Location
    Oakland, CA
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Macro to consolidate entries from days to weeks

    Hi Jindon,

    You're absolutely correct the second tomato entry was off, thanks for catching that!

    Also, I think your macro is excellent and solves my issue - if you have time would you mind adding comments into the code so I can better understand what's going on? I'm still extremely new to VBA so I'm not sure what each line of code means.

    Thanks for your assistance!

  6. #6
    Registered User
    Join Date
    10-15-2012
    Location
    Oakland, CA
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Macro to consolidate entries from days to weeks

    Hi Jindon,

    I noticed 2 things that I could use some assistance with:

    1) The code doesn't seem to work when I use non-2013 dates

    2) The values don't appear if the Food and Food2 values don't match for an entry. They aren't necessarily equal, because the difference is consistent for each food (e.g. food will be Tomato and food 2 would be Tomato_2). The adjustment look-up could use either one, but preferably it would match Food.

    Can you help me with these points?

    Thanks!

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

    Re: Macro to consolidate entries from days to weeks

    My code is not count Food2 in consideration.

    Can you explain about Food and Food2 for the calculation?

  8. #8
    Registered User
    Join Date
    10-15-2012
    Location
    Oakland, CA
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Macro to consolidate entries from days to weeks

    Hi Jindon,

    When I changed the values under Food and Food2, the values in the Value column don't appear after I run the macro. Even when one of the values is the same as the adjustment table, it doesn't seem to show when I run the macro.

    Which column does the code read to adjust the value in the export?

    Also, can it be adjusted to work with non-2013 dates?

    Thanks!
    Last edited by Seraph122; 01-04-2013 at 08:00 PM.

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

    Re: Macro to consolidate entries from days to weeks

    Please Login or Register  to view this content.
    Should take care of different year.

    I just don't understand the relation between Food & Food2 for calculation.
    In other words, don't understand the reason for FOOD2 at all.

    If you upload the file with different situation with the result, it might help me to understand.

  10. #10
    Registered User
    Join Date
    10-15-2012
    Location
    Oakland, CA
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Macro to consolidate entries from days to weeks

    Hi Jindon,

    Thanks for your help so far!

    Food 1 and Food 2 simply correspond - for example every time Food 1 is Tomato, then Food 2 is Ketchup. Every time it is Cheese, then Food 2 is Fondue. If you can make Food 1 column the one that corresponds to the Adjustment table, that would be great. I updated the data to show what I'm talking about. Food 2 just needs to be part of the export data, it doesn't have to touch any of the calculations.

    Also, could you help me tweak it so that it adds to the "Output" worksheet? I'm super new to VBA so it's still kinda confusing. I'm trying my best to walk through your macro but it seems too advanced for me at the moment .

    Thanks!
    Attached Files Attached Files

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

    Re: Macro to consolidate entries from days to weeks

    Change 3 to 2
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    10-15-2012
    Location
    Oakland, CA
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Macro to consolidate entries from days to weeks

    Hi Jindon,

    That worked perfectly!

    Can you tell me how to make the macro put the output results on a new worksheet called "Output"?

    Thanks!

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

    Re: Macro to consolidate entries from days to weeks

    Try this
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    10-15-2012
    Location
    Oakland, CA
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Macro to consolidate entries from days to weeks

    Jindon,

    This works great!! I really can't thank you enough!!

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

    Re: Macro to consolidate entries from days to weeks

    Re your PM

    If you step through the code, you will see variable "txt".

    temp = Join$(Array(WorksheetFunction.WeekNum(a(i, 2)), a(i, 3), Year(a(i, 2))), Chr(2))

    a(i,2) = Col.2, holds the date.
    a(i,3) = description
    Year(a(i,2)) = Year of the date in co.B
    WeekNum Excel function returns Week number of the date of its year.

    So concatenating these data in a string makes Unique key for the output.

    How to step through the code.
    While you are in VBE;
    1) click on somewhere on the code.
    2) as you hit F8, the code will execute line by line.
    3) if the line past that line, place the cursor on the variable "txt" and you will see the contents.

  16. #16
    Registered User
    Join Date
    10-15-2012
    Location
    Oakland, CA
    MS-Off Ver
    Excel 2010
    Posts
    43

    Re: Macro to consolidate entries from days to weeks

    Excellent - thanks Jindon!

+ 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