+ Reply to Thread
Results 1 to 24 of 24

Add up based on given values - VBA

  1. #1
    Registered User
    Join Date
    07-18-2012
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2010
    Posts
    17

    Add up based on given values - VBA

    Dear Friends,

    I am tied up with many issues while programming for a bigger project.
    Kindly refer to the attached excel file.

    Column named 'CSQ Name' contains the call center descriptions for various departments and vehicle franchise.
    I need a report that has only CSQ Names that end with 'FORD', 'JLR', POC' and 'FM' (valid ones). Rest are ignored.
    In a particular valid CSQ Name say 'CEN-ENG-SAL-FORD' I need to know how many 1s are read in the 'Disposition' column. Plus I need the total count for both dispositions, 1 and 2.
    The above should be done for all valid CSQ Names.

    Kindly advise how I would go about it using VBA.
    I need the most efficient method, as this is just a part of a bigger project and involves 70,000+ rows.
    Sample result report also shown in 2nd sheet.

    Much appreciate any help in this regards,
    Philip
    Attached Files Attached Files
    Last edited by pjacob; 10-29-2014 at 02:05 PM. Reason: grammar

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Add up based on given values - VBA

    I'm thinking of a Dictionary approach with the Keys incremented per Item
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    07-18-2012
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Add up based on given values - VBA

    Hi xladept,

    Thank you for your immediate response.

    Yes, I read about it the whole night yesterday and checked out various codes as well.
    That and the collection method too.
    But somehow I am not able to get my head around it.
    Must be I am tensed due to month end pressures and overwhelmed with new learning in the mid of the night! Lol.
    Plus I am not able to integrate all the requirements I mentioned above.

    Could you be kind enough to provide me with a complete code on this please; that involves all the steps I mentioned.
    I can't tell you how desperate I am and thankfull I would be.

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Add up based on given values - VBA

    I'll see what I can do - tomorrow!

  5. #5
    Registered User
    Join Date
    07-18-2012
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Add up based on given values - VBA

    Yes, that's fine.
    I have got time till 2nd November before I do the final test runs.
    Just so you know, I have been doing VBA programming in Excel/Access for quite sometime now (10+ years).
    However, I work for an automobile company as a sales administrator.
    So, programming is not my job requirement here and therefore don't get much time to learn further except through the various on and off project challenges that I am provided with from other departments.
    Dictionary is a new one...

    Thanks so much for your consideration.
    Good Day.
    Philip

  6. #6
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Add up based on given values - VBA

    May be we can arrive it using Countif() function.

    But please let us know where is your expected result and how you are arriving it for giving exact solution


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  7. #7
    Registered User
    Join Date
    07-18-2012
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Add up based on given values - VBA

    Hi Sixthsense,
    The excel file posted contains the data(Sheet 1) and required result(Sheet 2)
    My first post also mentions how I arrive at these results.

    Anything further I am expected to clarify do let me know.

    Thanks,
    Philip

  8. #8
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Add up based on given values - VBA

    Considering the Data Size can we go for Pivot Table?

    Please confirm

  9. #9
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Add up based on given values - VBA

    I am really confuse about how you are arriving the values

    Can you please explain it for these two from your expected result?


    A
    B
    C
    1
    CSQ Name
    Calls Presented (1s and 2s)
    Calls Handled (1s)
    2
    ALA-ARA-SAL-FORD
    116
    89
    3
    ALA-ARA-SAL-JLR
    134
    110

  10. #10
    Registered User
    Join Date
    07-18-2012
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Add up based on given values - VBA

    Any method is fine with me, however it need to be done via VBA.
    My clients are least bothered with the method but more concerned with speed, accuracy & user usage simplicity.

    Explanation:

    If there is an occurance of 'ALA-ARA-SAL-FORD' and the corresponding 'Disposition' reads '1', then say a 3 dimension(3D) array would be updated with '1' and the 3D also updates as '1'.
    'ALA-ARA-SAL-FORD' ---------- 1-------------- 1
    If there is a second occurance, program would check again the 'Disposition' column. If it reads '1', then the new array value would be updated as:-
    'ALA-ARA-SAL-FORD' ---------- 2-------------- 2
    If however, on another occurance 'Disposition' reads '2' then the array would be updated as:-
    'ALA-ARA-SAL-FORD' ---------- 2-------------- 3

    Hope this clarifies...
    I don't know how to be more clear than this... :-)

    Thanks,
    Philip
    Last edited by pjacob; 10-30-2014 at 03:21 AM. Reason: additional statement

  11. #11
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Add up based on given values - VBA

    The ALA-ARA-SAL-FORD* is available only in 4889 row alone.

    Without any proper description I cannot go further...

  12. #12
    Registered User
    Join Date
    07-18-2012
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Add up based on given values - VBA

    Yes, that was only a sample file with less data.
    I have now included one with more data.
    Attached Files Attached Files

  13. #13
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Add up based on given values - VBA

    Quote Originally Posted by pjacob View Post
    Yes, that was only a sample file with less data.
    I have now included one with more data.
    Please don't waste our time

    When you show the sample (limited) data then you should have adjusted the expected result also.

    That is the reason in three continuous posts I have asked for the description about how you are arriving the expected result. But you simply said that is the expected result.

    We are not here to do the data study since your sample data was 8000 rows of data.

    Sorry I cannot continue with this thread since I feel I am wasting my time, I hope someone will provide you the solution.

    Best of luck!

  14. #14
    Registered User
    Join Date
    07-18-2012
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Add up based on given values - VBA

    Adious & really appreciate your time.
    You seem offended. Sorry about that.
    Good Day.

    Best Regards,
    Philip

  15. #15
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,607

    Re: Add up based on given values - VBA

    pjacob,

    only you need to do is to create smaller example, with just few names and EXACT output based on that solution.

  16. #16
    Registered User
    Join Date
    07-18-2012
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Add up based on given values - VBA

    Hi zbor,

    I am quite new to these forums.
    I have read the rules though & keep upto it.

    It did not pass me that I had to provide data and result as Exact, neither was such matter mentioned in the rules.
    I thought an expert might understand a sample with an explanation given.
    Now, that I have understood your recommendation, I am working on it right now and will post the exact data->result in a while. Thank you.

    Just to point out though from the forum rules...
    A vicious delivery may result in possibly good suggestions being ignored. Don't be the cause of that.
    •No matter how angry or upset you may be over any issue, courteous discourse will be expected at all times.

    I should be the one offended from that matter; refer the earlier post(sithsense) being very rude.
    But I have taken it lightly in the spirit of obtaining the answer from other experts/professionals.

    Thanks,
    Philip
    Last edited by pjacob; 10-30-2014 at 06:57 AM. Reason: Grammar

  17. #17
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,607

    Re: Add up based on given values - VBA

    Quote Originally Posted by pjacob View Post
    It did not pass me that I had to provide data and result as Exact.
    I thought an expert might understand a sample with explanation.
    You need to provide result that is understandable.
    If it's not keep explaining but be more descriptive.

    What is clear to your doesn't have to be clear to other.
    Sometimes we can guess but also if we don't get right clue we might lose hours just to figure out something you didn't explain well in first place.

  18. #18
    Registered User
    Join Date
    07-18-2012
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Add up based on given values - VBA

    Yes, Sir.
    Got it.
    Will adhere to that.
    Won't repeat it ever again, I promise.
    Last edited by pjacob; 10-30-2014 at 07:06 AM. Reason: Additional statement

  19. #19
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Add up based on given values - VBA

    Hi Philip,

    try this:

    Please Login or Register  to view this content.
    Last edited by xladept; 10-30-2014 at 11:18 PM.

  20. #20
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Add up based on given values - VBA

    * Obviously, the code is based on your original sample

  21. #21
    Registered User
    Join Date
    07-18-2012
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Add up based on given values - VBA

    Hi xladept,

    Thank you very much.
    I have just read through your code and in the initial analyses itself, I can vouch that this is exactly what I am looking for.
    I am not at work today, as it is weekend in this part of the world.
    I will implement this first thing on Saturday at office and will let you know on the outcomes.
    No worries, I am sure this is as per the logic I mentioned and so the actual set of data does not matter.
    Besides, now that I have the basic codes to work on a dictionary object and the concept itself, I can easily improvise on this, if any changes is required.

    Really appreciate your time on this.

    Just a query though, is the dictionary object initialized with the sheet1 range?
    I don't seem to have found any line to that effect. Maybe it was an oversight?
    Please let me know.

    I am going to mark your reputation on this and leave the thread as is.
    Once I run the code and every query is dealt with to satisfaction, I would mark the code as solved.
    I am guessing that's how things are done around here... Is it?

    Good Day & Many Thanks,
    Philip
    Last edited by pjacob; 10-31-2014 at 04:47 AM. Reason: Grammar

  22. #22
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Add up based on given values - VBA

    Hi Philip,

    Thanks for the rep!

    I'm glad you like my code

    The dictionaries, I used two, are named B and O - They are separate from the sheet, they are dimensioned as objects and

    Please Login or Register  to view this content.
    This code enables them and

    Please Login or Register  to view this content.
    This code initializes the respective keys (which I named Key in the code).

    After the first, and only pass:

    Please Login or Register  to view this content.
    This code declares the key array and the items by key are the accumulation of B both 1 and 2 and O just 1's.

  23. #23
    Registered User
    Join Date
    07-18-2012
    Location
    Abu Dhabi, UAE
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Add up based on given values - VBA

    Hi xladept,

    I have implemented your code and tested it on 52,000 rows of data.
    Real fast & accurate - Perfect.

    Thanks a million.

    Below is the code I used, without much change at all.

    Please Login or Register  to view this content.

  24. #24
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Add up based on given values - VBA

    Hi Philip,

    Excellent! Glad to hear that it's perfect, you've commented the code nicely

    Orrin

+ 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. Replies: 4
    Last Post: 05-19-2015, 11:53 PM
  2. Loop based on two values and then Copy based on numbers between the two values
    By mintsaucesheep in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-20-2013, 09:43 AM
  3. Replies: 9
    Last Post: 04-18-2013, 09:27 AM
  4. [SOLVED] Filtering and generating new tabs based on Unique values based in column
    By amlan009 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-02-2012, 09:40 PM
  5. Replies: 4
    Last Post: 06-28-2012, 07:08 AM

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