+ Reply to Thread
Results 1 to 8 of 8

Excel Macro that merges duplicates and adds two calculations

  1. #1
    Registered User
    Join Date
    02-27-2016
    Location
    London
    MS-Off Ver
    MS Office 2010
    Posts
    12

    Excel Macro that merges duplicates and adds two calculations

    Hello all,

    I am looking to create a macro that does the following:

    The script has to find the "average days unscheduled" from items with similar name.

    For example, Finance appears twice, one with days unscheduled 20 and another 2. So the average days unscheduled is 11.
    Finance2 appears only once so average # of days unscheduled is 5 and so on.

    So one step is to calculate the average # of days unscheduled for the values that have the same name
    and another step is to find the count of the values of the same name, and remove/hide the duplicates.

    Doing it manually, I know can do do a countif to get the # of times the value is repeated, and then highlight Days unscheduled for the same name and look at the average, I'd like to know to have a macro do the same thing quicker.

    Thanks in advance for any help you guys can provide!!
    Attached Files Attached Files
    Last edited by jodo2; 02-27-2016 at 09:36 PM.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,334

    Re: Excel Macro that merges duplicates and adds two calculations

    Hi jodo and welcome to the forum,

    No VBA or code needed. Simply learn a little about Pivot Tables. See the attached.

    PT for Jodo.xlsx
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    02-27-2016
    Location
    London
    MS-Off Ver
    MS Office 2010
    Posts
    12

    Re: Excel Macro that merges duplicates and adds two calculations

    That's so easy, thanks Marvin! I have some follow up questions on this, should I create a new thread or post in here?

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,334

    Re: Excel Macro that merges duplicates and adds two calculations

    Here is ok if it is of the same workbook.

    I could have made the source of the pivot table a Dynamic Named Range (DNR) and updated it whenever something changed in your table. Is that your question?

    I just threw the above into the attached, so it auto updates and the Pivot will use the DNR. Took 3 minutes... (Add Reputation ?)

    PT for Jodo Better.xlsm
    Last edited by MarvinP; 02-27-2016 at 10:15 PM.

  5. #5
    Registered User
    Join Date
    02-27-2016
    Location
    London
    MS-Off Ver
    MS Office 2010
    Posts
    12

    Re: Excel Macro that merges duplicates and adds two calculations

    That's great, I really like how you also commented and listed in the file exactly what you had done.

    I was able to follow your instructions to do it from scratch as well myself (well I had to google DNR's and how to use them and now it makes sense, then I couldn't figure out how to refresh PT's, which I learned how to do as well as the macro you used to refresh it ActiveWorkbook.RefreshAll) great stuff!

    What I need to do is show only unscheduled meetings, and hide the meetings that are fully scheduled and keep a daily tally on meetings scheduled. Once a certain amount of meetings are scheduled, they are removed from the data.

    Maybe I should create another thread for my second part of the question? So every day, for each entry I need to say "this many meetings scheduled on this day" and then I need a totals for the value and totals overall for day and grand total. I figured I could just include that in the original data and have the PT load it up for me. I'm obviously doing something wrong, the total should be grand total should be 33 in my example, but it's all messed up. I guess it must be the data range I selected, shouldn't include totals? Do I even need a totals in my original data or can I just the PT to create it for me?

    The other part I'm having a lot of trouble with is that since the data changes daily, how do I merge it with the existing tally? So let's say I get a new report, it has the new data for meeting name and days unscheduled. I can copy/paste that data as is into the DNR, but then it doesn't match with the daily tally. So for example let's say the new data only has 4 values, the previous meetings have been scheduled. I included it in tab "Data Day 2". Some of the values are the same, except the days unscheduled goes up by 1. But then some are gone, and some are new. I want my tally to continue, but the new data needs to be included. I could manually see all the new values that match, and then add them in manually, without deleting my old values, but that would take forever.

    What I was thinking is, would there be a way to hide the values that aren't in the new data somehow, and only show the new data which is meetings unscheduled. This seems too complicated to me, I'm confusing myself.
    Attached Files Attached Files

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,334

    Re: Excel Macro that merges duplicates and adds two calculations

    Hey Jodo,

    It's great that you found the DNR and saw how the PT was updated when the sheet was selected. I think you need a little better table structure to do what I think you need. It seems to me you may need to keep track of meetings that are going on in different areas or in groups. See my new sheet where I've added a Date field. I then used this field in the Pivot Columns area. You can filter this column using DATEs. I think you should simply keep adding to the table all those meetings and filter in the pivot to see and count what you need. No need to remove data in columns A to C... See if this makes sense or gets you closer to what you want.

    Schedule Using Groups Rooms Dates Event DNR.xlsm

  7. #7
    Registered User
    Join Date
    02-27-2016
    Location
    London
    MS-Off Ver
    MS Office 2010
    Posts
    12

    Re: Excel Macro that merges duplicates and adds two calculations

    Hey Marvin, sorry I don't think sorry that this is what I had wanted, or maybe I don't understand it correctly.
    I apologize I wasn't clear in my explanation, you expended effort to solve my issue, I really appreciate it. It seems like we are very close, but I don't know how to change the way you created the PT to the original PT.

    I like the original Pivot Table, it accomplished half of what I need. The grand totals part is good, I need to add that to the calculation. The rest is I need to keep a continuous tally of meetings scheduled, I don't need to worry about the room or groups.

    Let me try to explain a little better:, I want to track the # of meetings scheduled per day and keep the record of it.

    So I need the name of the meeting, the average # of days unscheduled and the count of meetings with the same name. The same meeting names won't show up in the summary twice, so the PT accomplished that perfectly and the average and count as well. That part is essential, but then after that, I need to also track a daily tally as well, which I guess would build over time.

    So let's say day 1 had data like:

    Meeting 1 unscheduled 20 days
    Meeting 2 unscheduled 9 days

    And then we scheduled one of the two meetings on Feb 28. The data should reflect on what day the meeting was scheduled.

    Now on day 2 we have, two new instances of "meeting 3"

    Meeting 2 unscheduled 10 days
    Meeting 3 unscheduled 1 days
    Meeting 3 unscheduled 1 days

    So now we have meeting 1 which is already scheduled and should have a tally of 1 on Feb 28. And then I have to include these new data into the PT which I will copy/paste from the data sent to me.

    On day 3, the data changes because Meeting 2 was scheduled and can be removed from the list of ongoing unscheduled meetings, but should remain in the tally of being scheduled on Feb 29. The grand total would be 2 meetings scheduled.

    Meeting 3 unscheduled 2 days
    Meeting 3 unscheduled 2 days
    Meeting 4 unscheduled 1 days

    When it's a small data set, I could easily add/remove them, but I'm worried with 50+ items, it's going to be a bit more difficult to keep track of, but still is doable.

    I wanted to add that the new items I get also have a unique identifier as well. I don't know if that makes a difference?

  8. #8
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,334

    Re: Excel Macro that merges duplicates and adds two calculations

    Hi jodo,

    Part of my confusion on what you want is the word "unscheduled". I'm thinking you are a facilities coordinator overseeing 10 buildings, all of which have 3 meeting rooms. You get email from Boss1 who says s/he needs to schedule a meeting in building 2 at noon Friday for an hour. You look at building 2 and see room 3 is available at noon. You then put that data into my table and send email back to Boss1 telling them what room they have at noon on Friday.

    To UNSchedule something it needs to be on the active schedule in the first place. It seems like your word of UnSchedule is the same as my Schedule.

    I think you need to open my last workbook and look at the Pivot List and drag and drop some of the fields. Then you need to read about showing the pivot's subtotals and grand totals and how to compact or repeat rows.

    Watch this video that shows design options in Pivots:
    http://www.bing.com/videos/search?q=...98&FORM=VRDGAR

+ 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. Macro to find duplicates, concatenate cells, then delete old duplicates
    By givemepuppies in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 03-04-2016, 02:43 AM
  2. [SOLVED] Excel Macro Step that Duplicates Dragging Fill Handle Down
    By Quinn.Farley in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-05-2015, 12:39 PM
  3. Replies: 8
    Last Post: 11-16-2014, 12:07 PM
  4. [SOLVED] Macro to find duplicates, concatenate Unique Values, then delete old duplicates
    By lesoies in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-17-2013, 04:32 PM
  5. Replicate Remove Duplicates icon using a macro in Excel Mac 2011
    By Liesl123 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-16-2012, 09:13 AM
  6. Replies: 17
    Last Post: 07-05-2011, 05:37 PM
  7. Macro to check for duplicates and highlight duplicates
    By obc1126 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-23-2008, 09:55 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