+ Reply to Thread
Results 1 to 13 of 13

Coding for a search and count array using VB

  1. #1
    Registered User
    Join Date
    11-22-2010
    Location
    Boston, MA
    MS-Off Ver
    Excel 2007
    Posts
    28

    Coding for a search and count array using VB

    Hello All,

    I have an excel formula that works great. The problem is that This formula is repeated 5 times in each cell (to represent each worksheet that needs to be summarized and counted). There are 10 cells with this formula and it crashes my system every time I try to save it. The one time I did save it, it took 40 minutes. Here is the formula in short version:

    Please Login or Register  to view this content.
    I need to find a way to do this via macros in hopes that my spreadsheet will not die every time I add something.

    Basically, what I am trying to do is see if in Column G you find EC1
    If you find EC1, I need to know if column D is populated and count up how many times this happens over 5 spreadsheets.
    The catch is that if D is repeated within the same spreadsheet, I do not want the repeats to be counted.
    These are spreadsheets that are constantly growing so I have set the following code, so far but I am not sure I am on the right track. I was thinking about a few if then statements, but am new at the coding and do not know how to program for the duplicates.

    Please Login or Register  to view this content.
    Is there anyone that can help me with the vb programing for this. I am attaching a spreadsheet that may help show my problem.

    Thank you in advance for any and all assistance.
    Much Regards,
    jsgray
    Attached Files Attached Files
    Last edited by jsgray; 01-24-2011 at 10:00 AM. Reason: Solved

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Coding for a search and count array using VB

    Hello jsgray,

    Just to be sure I follow you correctly, the sum for the example in the workbook would be 8, yes?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Coding for a search and count array using VB

    I suspect were you to add some Dynamic Named Ranges you might notice some improvement in performance

    Presently you're referencing >65000 cells in each precedent range - Arrays are iterative by nature and do not (unlike most functions) work with just the used range intersect.

    Create a Name

    Please Login or Register  to view this content.
    with the above in place your unique count formula becomes:

    Please Login or Register  to view this content.
    So now the above is only referencing the necessary rows - that said if you have tens of thousands of rows of data then it will still be slow.

  4. #4
    Registered User
    Join Date
    11-22-2010
    Location
    Boston, MA
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Coding for a search and count array using VB

    Hello Leigh,

    The answer is 8. Thank you for your time and assistance.

    Regards,
    Justin

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Coding for a search and count array using VB

    Hello Justin,

    Do you want totals for each sheet in different cells or a single grand total in one cell?

  6. #6
    Registered User
    Join Date
    11-22-2010
    Location
    Boston, MA
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Coding for a search and count array using VB

    Hello Leith,

    I am going to need all sheets totaled.

    Thank you again for your time.

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Coding for a search and count array using VB

    Hello jcgray,

    The following UDF has been added to the attached workbook. This will sum all "EC1" values on all the worksheets. Repeats in column "D" are ignored.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    11-22-2010
    Location
    Boston, MA
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Coding for a search and count array using VB

    Thank you Leith,

    This works to calculate the number of times that there is EC1 and Something in column D, in the worksheet you have supplied. In my full sheet, I am getting the total number which includes the duplicates. Is there check that I can apply to see where the code is missing the duplicates in the created Dictionary.

    Also, My original vision was to use the code as a Command Button where I press the button and it populates the whole spreadsheet. Is it possible to amend this code to fit in a command button as I get an error when I try it (looking for end sub prior to the Function command). How can I do this without using the function command.

    This newbie appreciates all of your assistance, and time. Thank you graciously. Anything you can do to help is always gratfully accepted and valued.

    Thanks,
    Justin

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Coding for a search and count array using VB

    Hello Justin,

    I can better answer your questions if you post your workbook.

  10. #10
    Registered User
    Join Date
    11-22-2010
    Location
    Boston, MA
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Coding for a search and count array using VB

    Thank you for your time and assistance Leith,

    I am leaving for the day. I have to step away from this for a few. I can tell you I have played slightly with the formula and of the codes that I need I have got a few to work perfectly and the EC1 and EC2 are still counting Dups. I am going to continue playing with this for a little. If I have further questions I will contact you (in the forum) next week.

    I cannot tell you how much I appreciate your help. Thank you very much.

  11. #11
    Registered User
    Join Date
    11-22-2010
    Location
    Boston, MA
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Coding for a search and count array using VB

    Hello Leith,

    Hope all is well. I had to get away from the file to see what was really going on. Your formula works perfectly, if there were no blanks in the dataset. It is reading a blank as a word, then not counting the rest of them. I am attaching another spreadsheet that exemplifies the issue, in hopes that you can help me find a solution that if D=nothing then do not count the cell. All of your assistance is appreciated. Thank you for your time and assistance.

    Highest Regards,
    Justin
    Attached Files Attached Files

  12. #12
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Coding for a search and count array using VB

    Hello Justin,

    The macro now ignores blank cells. On "Sheet1" is now a button to run the macro. The total is copied to "C21". You can change this whichever location you want. The attached workbook has all these changes made to it.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    11-22-2010
    Location
    Boston, MA
    MS-Off Ver
    Excel 2007
    Posts
    28

    [Solved]Re: Coding for a search and count array using VB

    Thank you Leith,

    Your time and patience is greatly appreciated. This works beautifully.

    Regards,
    Justin

+ 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