Results 1 to 10 of 10

Excel VBA Code Instead of SumIf Array Formula for Unique Values

Threaded View

  1. #1
    Registered User
    Join Date
    07-15-2013
    Location
    Arizona
    MS-Off Ver
    Excel 2016
    Posts
    64

    Question Excel VBA Code Instead of SumIf Array Formula for Unique Values

    Hello Forum,

    I have a set of data that is approximately 50,000 rows and need to do a summing function of the number of distinct values in one column that share a common value in another column. I've used the array formula {=SUM(IF(FREQUENCY(IF($B$2:$B$43134=B2,$A$2:$A$43134),$A$2:$A$43134)>0,1))} in the past and while it works it is EXTREMELY slow on our company network and my little HP laptop that could...takes hours and I literally need to leave it running overnight on the docking station and pray there isn't a forced reboot going on that night! I also have to do a similar sum if logic for two other columns. The results feed a model that I use pivot tables to determine percentages eligible, totals, etc.

    So I'm looking for VBA code that will loop through the data rows much faster than using the above type array formula or VBA that uses formula logic. I'd like to be able to use a macro button to control when the event occurs, but would like the code to run through every row and provide a result for each. I saw this link for count-ifs, but couldn't make it work for my situation and I'm hoping for similar lightning speed!

    http://www.excelforum.com/excel-prog...-countifs.html

    I've attached a much more simplified sample workbook that hopefully shows what I'm trying to accomplish, but essentially values in column A all tie to a value in column B. The relationship could be 1:1 or 1:many, basically it's the number of products (column A) on an account (column B). So for each value in column B, sum the total number of unique values in column A and put the result in column C. So for my sample workbook account 8888 has 3 unique values, 9797 has 2, and 1111 has 1. I tried to record a macro and it works one at a time, but would image even if I got it to work on the entire range with a single click of a command button it may still be very slow.

    UnqVals.PNG

    As always appreciate any help and thank you in advance!

    Best regards,
    Chris
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Array formula to extract and sort unique values from two worksheets
    By rshukla in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-07-2013, 06:11 AM
  2. add to array formula to only return unique values
    By jason892 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-11-2013, 06:39 AM
  3. [SOLVED] Count unique values in list but NOT using ARRAY formula
    By alx0101 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 03-15-2013, 08:15 AM
  4. Replies: 3
    Last Post: 11-24-2011, 06:11 AM
  5. Replies: 6
    Last Post: 06-14-2011, 07: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