+ Reply to Thread
Results 1 to 41 of 41

Macro to find the sum of shares against each name

  1. #1
    Forum Contributor
    Join Date
    06-05-2014
    MS-Off Ver
    Microsoft Office Professional Plus 2016
    Posts
    155

    Macro to find the sum of shares against each name

    Hi Team,

    Need help to create macro for the manual activity that i does.

    I have data like attached where each resource holds share in many projects. I need resources who have sum of shares as more than 100 (sum of share across all projects) to be in one sheet and resources with sum of shares less than 100 (sum of share across all projects) to be in another sheet. Resources with sum of shares as exactly 100 should be ignored.

    The ID is unique for each resource. So i usually creates a pivot with ID and sum of shares, then copy paste the “above 100 shares” and “less than 100 shares” to the respective sheets.

    I have did the same manual activity for the attached sample and pasted the “above 100 shares” and “less than 100 shares” in the respective sheets.
    Please help me with codes to automate this.
    Attached Files Attached Files
    Last edited by arun.sj; 07-28-2015 at 02:25 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    02-06-2014
    Location
    N/A
    MS-Off Ver
    N/A
    Posts
    373

    Re: Macro to find the sum of shares against each name

    Try this... (macro workbook attached, run update sub)

    Please Login or Register  to view this content.
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    06-05-2014
    MS-Off Ver
    Microsoft Office Professional Plus 2016
    Posts
    155

    Re: Macro to find the sum of shares against each name

    Hi,

    Thanks for replying.
    This is not working in the way that I was expecting.. let me explain in detail.

    I want the people whose sum of shares more than 100 to be placed in sheet “share above 100”. As per the attached sample, Arun’s share is 135 (sum of shares across all projects) and similarly Arjun’s share is 315. Since both of these people have more than 100, these 2 names alone have to be placed in sheet “share above 100”.


    In the same way Patric’s share is 60 (sum of shares across all projects) and similarly Vimal’s share is 1. Since both of these people have less than 100, these 2 names alone have to be placed in sheet “share below 100"

    I have pasted the details that has to come in the sheets “above 100 shares” and “less than 100 shares.. I am looking for the same details after applying the codes.

    Please help me..

  4. #4
    Forum Contributor
    Join Date
    06-05-2014
    MS-Off Ver
    Microsoft Office Professional Plus 2016
    Posts
    155

    Re: Macro to find the sum of shares against each name

    Hi Team, Please help

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to find the sum of shares against each name

    Hi arun.sj

    What it it's equal to 100 (David)?
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

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

    Re: Macro to find the sum of shares against each name

    You want to exclude the 100 shares in total....
    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Macro to find the sum of shares against each name

    For the fun another one
    Note:
    in sheet "Share below 100" is included total share =100
    if you want the opposite change
    "If (ObjDic1.Item(K) > 100) Then" to "If (ObjDic1.Item(K) >= 100) Then"
    Please Login or Register  to view this content.
    - Battle without fear gives no glory - Just try

  8. #8
    Forum Contributor
    Join Date
    06-05-2014
    MS-Off Ver
    Microsoft Office Professional Plus 2016
    Posts
    155

    Re: Macro to find the sum of shares against each name

    Quote Originally Posted by jaslake View Post
    Hi arun.sj

    What it it's equal to 100 (David)?
    Hi John, if the sum of shares is equal to 100, it should be ignored.. Only above 100 shares and less than 100 have to be pasted to the respective sheets..

  9. #9
    Forum Contributor
    Join Date
    06-05-2014
    MS-Off Ver
    Microsoft Office Professional Plus 2016
    Posts
    155

    Re: Macro to find the sum of shares against each name

    Quote Originally Posted by jaslake View Post
    Hi arun.sj

    What it it's equal to 100 (David)?
    Hi John, if the sum of shares is equal to 100, it should be ignored.. Only above 100 shares and less than 100 have to be pasted to the respective sheets..

  10. #10
    Forum Contributor
    Join Date
    06-05-2014
    MS-Off Ver
    Microsoft Office Professional Plus 2016
    Posts
    155

    Re: Macro to find the sum of shares against each name

    Quote Originally Posted by jindon View Post
    You want to exclude the 100 shares in total....
    Please Login or Register  to view this content.
    Thanks for replying.. I am getting syntax error..

    Can you help me by updating the codes in the sample attached please.

  11. #11
    Forum Contributor
    Join Date
    06-05-2014
    MS-Off Ver
    Microsoft Office Professional Plus 2016
    Posts
    155

    Re: Macro to find the sum of shares against each name

    Quote Originally Posted by jindon View Post
    You want to exclude the 100 shares in total....
    Please Login or Register  to view this content.
    Thanks for replying.. I am getting syntax error..

    Can you help me by updating the codes in the sample attached please.

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

    Re: Macro to find the sum of shares against each name

    Syntax error??
    Attached Files Attached Files

  13. #13
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro to find the sum of shares against each name

    Maybe:

    Please Login or Register  to view this content.

  14. #14
    Forum Contributor
    Join Date
    06-05-2014
    MS-Off Ver
    Microsoft Office Professional Plus 2016
    Posts
    155

    Re: Macro to find the sum of shares against each name

    Quote Originally Posted by PCI View Post
    For the fun another one
    Note:
    in sheet "Share below 100" is included total share =100
    if you want the opposite change
    "If (ObjDic1.Item(K) > 100) Then" to "If (ObjDic1.Item(K) >= 100) Then"
    Please Login or Register  to view this content.
    This is working..
    The only thing is share equal to 100 should be completely ignored which is not happening..
    Only share above 100 and below 100 should be available in the respective sheets..

    Please help..

  15. #15
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Macro to find the sum of shares against each name

    "share equal to 100 should be completely ignored " Yes it was prepared like that
    So use next code
    Please Login or Register  to view this content.
    Last edited by PCI; 07-30-2015 at 07:41 AM.

  16. #16
    Forum Contributor
    Join Date
    06-05-2014
    MS-Off Ver
    Microsoft Office Professional Plus 2016
    Posts
    155

    Re: Macro to find the sum of shares against each name

    Quote Originally Posted by jindon View Post
    Syntax error??
    This is working perfectly fine..
    I need your help to understand this code so I can make necessary changes when I use this in different files..

    Can you please help me by adding a comment beside the code so that I will be able to make changes.. Please help..

  17. #17
    Forum Contributor
    Join Date
    06-05-2014
    MS-Off Ver
    Microsoft Office Professional Plus 2016
    Posts
    155

    Re: Macro to find the sum of shares against each name

    Quote Originally Posted by JOHN H. DAVIS View Post
    Maybe:

    Please Login or Register  to view this content.
    This is working but have few minor issues.. After applying the codes, few cells are colored as in the heading in the sheet "share above 100"..

  18. #18
    Forum Contributor
    Join Date
    06-05-2014
    MS-Off Ver
    Microsoft Office Professional Plus 2016
    Posts
    155

    Re: Macro to find the sum of shares against each name

    Quote Originally Posted by PCI View Post
    "share equal to 100 should be completely ignored " Yes it was prepared like that
    So use next code
    Please Login or Register  to view this content.
    Thanks for replying .. unfortunately i am getting a "run-time error 9 :Subscript out of range" ..

    If you can update the codes in the sample file, it would be of great help.. Please help..

  19. #19
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Macro to find the sum of shares against each name

    The macro run OK with the sample you sent
    See attached
    Attached Files Attached Files

  20. #20
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro to find the sum of shares against each name

    I tested with your sample data and didn't have any issues. However, try this.

    Please Login or Register  to view this content.

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

    Re: Macro to find the sum of shares against each name

    You probably nedd to change
    Please Login or Register  to view this content.
    This creates the data set only columns that is necessary to work with, also match up with the column order to output heading.
    i.e
    ID Name Share Grade Location Supervisor Name
    2 3 4 6 7 8
    If you place Column "ID" in 1, "Share" in 3, no need to change the rest.

  22. #22
    Forum Contributor
    Join Date
    06-05-2014
    MS-Off Ver
    Microsoft Office Professional Plus 2016
    Posts
    155

    Re: Macro to find the sum of shares against each name

    Quote Originally Posted by PCI View Post
    The macro run OK with the sample you sent
    See attached
    This is working perfectly fine... .. Thank you so much for your help..

    need your help to understand the code.. requesting you to please explain me the codes so i can make changes while using it in diff files... Please help..

  23. #23
    Forum Contributor
    Join Date
    06-05-2014
    MS-Off Ver
    Microsoft Office Professional Plus 2016
    Posts
    155

    Re: Macro to find the sum of shares against each name

    Quote Originally Posted by jindon View Post
    You probably nedd to change
    Please Login or Register  to view this content.
    This creates the data set only columns that is necessary to work with, also match up with the column order to output heading.
    i.e
    ID Name Share Grade Location Supervisor Name
    2 3 4 6 7 8
    If you place Column "ID" in 1, "Share" in 3, no need to change the rest.
    Thanks for your reply.. Sorry but i need a bit more detailed since i am not that good with the codes..

    i understood the part [{2,3,4,6,7,8}]).. but when i tried with a diff sample by updating this part, the columns are placed correctly as expected but the details were incorrect .. like shares with below 100 values are also placed in sheet "Share above 100"..

    Please help..

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

    Re: Macro to find the sum of shares against each name

    Upload your original file with dummy data, but data layouts must be correct order.

  25. #25
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Macro to find the sum of shares against each name

    "need your help to understand the code"
    The code is very simple but you need first to understand how "Scripting.Dictionary" is working.
    There is 2 Dictionaries:
    - One to make the list of the ID and the sum of the share
    - One to make the list of the ID and the information attached to the ID
    A first part of the macro is preparing the Dictionary
    A second part of the macro is doing the display versus the sum of the share recorded in the first dictionary
    From first dictionary, depending of the sum, the corresponding ID is used to search in the second dictionary the corresponding information and display it.

  26. #26
    Forum Contributor
    Join Date
    06-05-2014
    MS-Off Ver
    Microsoft Office Professional Plus 2016
    Posts
    155

    Re: Macro to find the sum of shares against each name

    Quote Originally Posted by jindon View Post
    Upload your original file with dummy data, but data layouts must be correct order.
    Thank you so much for asking the original format.. Attached is the original file with sample data.. I have highlighted the columns that has to be brought to the sheets "Share above 100" and "Share below 100".

    The column which has the share value is column AN..

    Please help..
    Attached Files Attached Files

  27. #27
    Valued Forum Contributor
    Join Date
    09-17-2012
    Location
    Johannesburg, South Africa
    MS-Off Ver
    Excel 2007
    Posts
    454

    Re: Macro to find the sum of shares against each name

    And now for something completely different...

    over_share_cy.xlsm

    Please Login or Register  to view this content.

  28. #28
    Forum Contributor
    Join Date
    06-05-2014
    MS-Off Ver
    Microsoft Office Professional Plus 2016
    Posts
    155

    Re: Macro to find the sum of shares against each name

    Quote Originally Posted by PCI View Post
    "need your help to understand the code"
    The code is very simple but you need first to understand how "Scripting.Dictionary" is working.
    There is 2 Dictionaries:
    - One to make the list of the ID and the sum of the share
    - One to make the list of the ID and the information attached to the ID
    A first part of the macro is preparing the Dictionary
    A second part of the macro is doing the display versus the sum of the share recorded in the first dictionary
    From first dictionary, depending of the sum, the corresponding ID is used to search in the second dictionary the corresponding information and display it.
    Thanks a lot for explaining .. But sorry to bother you , i was trying to use this code to my original dump however i am getting error ..

    If you can help me by updating the codes in the attached file , i no more have to worry and it would be of great help.. Requesting for your help..

    I have highlighted the columns that has to be considered. The column which has the share value is column AN..

    Please help..
    Attached Files Attached Files

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

    Re: Macro to find the sum of shares against each name

    Please Login or Register  to view this content.

  30. #30
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Macro to find the sum of shares against each name

    No big difference
    Please Login or Register  to view this content.
    Last edited by PCI; 08-01-2015 at 03:39 AM. Reason: Code updated

  31. #31
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Macro to find the sum of shares against each name

    A remake
    ( Thx Jindon )
    Please Login or Register  to view this content.

  32. #32
    Forum Contributor
    Join Date
    06-05-2014
    MS-Off Ver
    Microsoft Office Professional Plus 2016
    Posts
    155

    Re: Macro to find the sum of shares against each name

    Quote Originally Posted by PCI View Post
    A remake
    ( Thx Jindon )
    Please Login or Register  to view this content.
    Thanks a lot for replying .. i am getting error that says "subscript out of range" for this code...

    but the code in your previous post : -

    Please Login or Register  to view this content.
    This code is working perfectly fine.. shall i consider this code ? do you think there should be any updates? please help

  33. #33
    Forum Contributor
    Join Date
    06-05-2014
    MS-Off Ver
    Microsoft Office Professional Plus 2016
    Posts
    155

    Re: Macro to find the sum of shares against each name

    Quote Originally Posted by jindon View Post
    Please Login or Register  to view this content.
    Thanks a Million Jindon This is working perfectly fine..

  34. #34
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Macro to find the sum of shares against each name

    "do you think there should be any updates? "
    No keep the first one, it is a technical more VBA improvement with no effect on the result.
    But can you give me more details where it stops and beter send the file for test.
    Last edited by PCI; 08-03-2015 at 03:11 PM.

  35. #35
    Forum Contributor
    Join Date
    06-05-2014
    MS-Off Ver
    Microsoft Office Professional Plus 2016
    Posts
    155

    Re: Macro to find the sum of shares against each name

    Quote Originally Posted by PCI View Post
    "do you think there should be any updates? "
    No keep the first one, it is a technical more VBA improvement with no effect on the result.
    But can you give me more details where it stops and beter send the file for test.
    Sure.. Attaching the file.. Requesting you to check..
    Attached Files Attached Files

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

    Re: Macro to find the sum of shares against each name

    Quote Originally Posted by arun.sj View Post
    Thanks a Million Jindon This is working perfectly fine..
    You are welcome and thanks for multiple reps.

  37. #37
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Macro to find the sum of shares against each name

    " i am getting error that says "subscript out of range" for this code..."
    Heu... yes because I changed the sheet's name
    Use next statement if you want to use the code : See "Data" changed to "Sheet1"

    Please Login or Register  to view this content.

  38. #38
    Forum Contributor
    Join Date
    06-05-2014
    MS-Off Ver
    Microsoft Office Professional Plus 2016
    Posts
    155

    Re: Macro to find the sum of shares against each name

    Quote Originally Posted by PCI View Post
    No big difference
    Please Login or Register  to view this content.
    Hi PCI .. Thanks for explaining in detail in this code..
    i need one more help before closing the thread.. After the data is pasted in both the sheets, it would be good if there is border across the data in both the sheets.. border in all the cells with black or blue color..

    Requesting for your help to update the above code..

  39. #39
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Macro to find the sum of shares against each name

    Is it what you want !

    Please Login or Register  to view this content.

  40. #40
    Forum Contributor
    Join Date
    06-05-2014
    MS-Off Ver
    Microsoft Office Professional Plus 2016
    Posts
    155

    Re: Macro to find the sum of shares against each name

    Quote Originally Posted by PCI View Post
    Is it what you want !

    Please Login or Register  to view this content.
    Yes.. That was exactly what i was looking for.. Thanks a Ton for the help.. The codes are working fantastic...

  41. #41
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Macro to find the sum of shares against each name

    Good news, and thank you for your thanks
    Enjoy Excel
    PCI

+ 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. Average cost of shares
    By shabouelezz in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 04-28-2014, 10:34 AM
  2. Searching in database of shares
    By Creatives in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-12-2013, 10:25 PM
  3. [SOLVED] How do I find the adress that shares the column of a certain cell and row of another?
    By groznij in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-10-2012, 08:22 PM
  4. Macro web query with changing url for shares
    By hiranparmar in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-24-2009, 02:28 PM
  5. IF function to profit when shares are up & down
    By microchod in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-15-2008, 09:13 AM
  6. Calculating shares
    By swingman39 in forum Excel General
    Replies: 4
    Last Post: 09-21-2008, 10:38 AM
  7. Macro that shares a workbook
    By iambalrog in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-15-2006, 08:18 AM

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