+ Reply to Thread
Results 1 to 12 of 12

Macro that would Copy/Paste to new sheet and remove duplicates

  1. #1
    Registered User
    Join Date
    05-02-2012
    Location
    Virginia
    MS-Off Ver
    Excel 2007
    Posts
    22

    Macro that would Copy/Paste to new sheet and remove duplicates

    Hi,

    I need a Macro that would on click of the 'Calculate' Button on top of a Quarter's column in the "Average" sheet:

    1) Copy and Paste the two columns from "ID" sheet in a new sheet
    2) Removes the duplicate 'ID' rows from the data in that new sheet
    3) Calculates the average of 'values' for a given quarter based on the data remained in the new sheet, given they are greater than zero and not texts
    4) Copy pastes the calculated average value under the 'Quarter' cells in the "Average" worksheet under the designated Quarter.
    5) Deletes that new temporary sheet that was used to do all the dirty work from the memory

    ID #s are unique and if they are repeated, they WILL have the same ' Quarterly value' for a given quarter. values for 2 different ID #s could potentially be identical so the macro shouldnt remove duplicates based on values. Only the duplicates based on ID # should be removed.

    preferably all this hidden behind the scenes and the only thing the user sees be the calculated average value in the cell right under the Calculate Button for the 'Quarter' column in the "Average" page.
    If you have any other suggestions that would be easier/better than the process above but would give me the result I want with click of the button, would also work too.

    test.xlsx

    Thanks alot

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

    Re: Macro that would Copy/Paste to new sheet and remove duplicates

    Give this a try

    Please Login or Register  to view this content.
    Thanks,
    Mike

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

  3. #3
    Registered User
    Join Date
    05-02-2012
    Location
    Virginia
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: Macro that would Copy/Paste to new sheet and remove duplicates

    Hey Mike,

    The code you gave me works great but at the same time too hardcore for me! I have to recreate this basically with a larger spreadsheet where the columns are spread apart and not necessarily right next to each other on the "ID" sheet. If its not too much work, would write a brief explanation here or maybe next to your codes as to what exactly is happenning each code line?. I understood that you are looping but couldn't quite follow what is happening in the loop or where the dups are being removed in your "scripting.dictionary" work sheet.

    Thanks

  4. #4
    Registered User
    Join Date
    05-02-2012
    Location
    Virginia
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: Macro that would Copy/Paste to new sheet and remove duplicates

    Also it was not clear to me what the function of variable n was in the code above?

  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: Macro that would Copy/Paste to new sheet and remove duplicates

    Hey dani_n88

    If you upload a workbook with your correct format i'll see what I can do.

  6. #6
    Registered User
    Join Date
    05-02-2012
    Location
    Virginia
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: Macro that would Copy/Paste to new sheet and remove duplicates

    Test Template.xlsm

    First sheet (“Unit”) could be ignored here.

    ******Average Method 1

    By clicking on the ‘Calculate Average 1’ Button in “Industry Average 1” sheet:
    For all the Quarters mentioned in the second row of the “Industry Average 1” sheet from the second column forward, Under each Quarter, called upon and recognized by its text (e.g. 1Q12, 2Q12, etc) and matched by that same quarter in the “Rate Calculation” Sheet,

    The ‘Reference Rates’ in the “Rate Calculation” the be SUMMED and COUNTED, from the first existing ‘ID 2’ Reference Rate in that page all the way to the last existing ‘ID 2’ Reference Rate,

    If the given conditions hold:

    1) The corresponding ‘ID 2’ numbers are not being double counted, (Two different internal codes could have the same ‘ID 2’ numbers, which means they are identical items but just have different internal codes, and therefore we do not want to count them twice).

    2) ‘Reference Rates’ are greater than zero and are numbers only
    Then the sum and the count are shown and the average is calculated by dividing the sum by the count for each called-up quarter.

    ******Average Method 2

    By clicking on the ‘Calculate Average 2’ Button in “Industry Average 2” Sheet:

    For each matched up Quarter between “Industry Average 2” sheet and the “Rate Calculation” sheet,

    1) Interests in the “Rate Calculation” sheet be summed up for all ‘ID 2’s for each called-up quarter, only if, both the interest and balance of that ‘ID 2’ are numbers and greater than zero and the ‘ID 2’ is not repeating. (no double counting)

    2) Balances in the “Rate Calculation” sheet be summed up for all ‘ID 2’s for each called-up quarter, only if, both the interest and balance of that ‘ID 2’ are numbers and greater than zero and the ‘ID 2’ is not repeating. (no double counting)

    3) The Count of all those ‘ID 2’s that had interests and balances of number type and greater than zero be displayed for each quarter

    4) The Average would show the total Interest for that quarter divided by the total balance for that quarter

    ******I would need the matching of Quarters in both sheet be dynamic. And whatever quarter I type in any cell of the second row, call up that quarter in the “Rate Calculation” sheet and display the results right under it.

    Sorry if its a lot or confusing. I've been trying to incorporate your original codes for the past 10 hours but just could figure out.

    I would really really appreciate the help Mike. Thanks man
    Last edited by dani_n88; 12-07-2012 at 06:58 PM.

  7. #7
    Registered User
    Join Date
    05-02-2012
    Location
    Virginia
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: Macro that would Copy/Paste to new sheet and remove duplicates

    Mike, I tried to be as clear as possible writing, that's why its so long! but please let me know if I can clarify more or explain better.

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

    Re: Macro that would Copy/Paste to new sheet and remove duplicates

    dani,

    Sorry Ive been preety busy lately. Yea its a little long for reading. But if you can list what sheets Industry Average 1 and Industry Average 2 output should look like it may be easier for me to understand.

  9. #9
    Registered User
    Join Date
    05-02-2012
    Location
    Virginia
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: Macro that would Copy/Paste to new sheet and remove duplicates

    Mike,

    Sorry I should have done that in the first place. here is what the Macro result should look like in the industry average 1 and 2 page. The results have a formula referenced to the correct location in the Rate Calculation sheet as a guide. please use the new file now.

    Test Template 2.xlsm

    Thanks

  10. #10
    Registered User
    Join Date
    05-02-2012
    Location
    Virginia
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: Macro that would Copy/Paste to new sheet and remove duplicates

    Just note that in each calculation, if any part of that Unit's data (Interest or Balance or Reference Rate) was zero or 'text' or negative for a given quarter, that whole Unit's data and count would not be included in the averaging.

  11. #11
    Registered User
    Join Date
    05-02-2012
    Location
    Virginia
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: Macro that would Copy/Paste to new sheet and remove duplicates

    any luck with the macro?

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

    Re: Macro that would Copy/Paste to new sheet and remove duplicates

    To be honest no. I don't think I can. I'll post a message and see if someone else may be able to help.

+ 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