+ Reply to Thread
Results 1 to 8 of 8

VBA - Counting unique values based on mutiple columns

  1. #1
    Forum Contributor
    Join Date
    12-06-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    201

    VBA - Counting unique values based on mutiple columns

    I got data similar to the following table (actual data will be the four date columns but further apart and many more rows):

    Capture.PNG

    Using VBA I want to count the unique values in col A where the date is equal to 16-Jan-16 in any of the four date columns (B, D, F and H).

    In the above example my answer should be 2 (MTN and DRD). MTN has 16-Jan-16 in two columns but must be counted only once.

    Is this possible without using multiple CountIf or CountIfs?

    Your help is appreciated.

    Edit: Forgot to add that some of the cells in the date columns might not have dates in them (empty cells/null value cells).
    Last edited by Bezzie; 05-08-2016 at 11:13 AM.

  2. #2
    Forum Contributor kalbasiatka's Avatar
    Join Date
    02-27-2016
    Location
    Brest, Belarus
    MS-Off Ver
    2021
    Posts
    224

    Re: VBA - Counting unique values based on mutiple columns

    Welcome! Show in the file what is and what should be in the end.
    To do it for me and help me it is 2 different things!
    Sorry for my english, blame Google translator

  3. #3
    Forum Contributor
    Join Date
    12-06-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    201

    Re: VBA - Counting unique values based on mutiple columns

    Data looks exactly like example given. There is just a bunch of columns between date columns with other information.

    As I said I want to do a unique count of values in col A where date = 16-Jan-16 in any of the four date columns.

    In the example 16-Jan-16 occurs 3 times but two of those times is where the same value is in col A (MTN - B5 and H4) so that must be counted as one. The other one is DRD in D8 so that one counts as one. So the unique count of values in col A where date (in any of the four columns) = 16-Jan-16 is 2. 2 is the answer I'm looking for in the example above.

    One problem is that some of the cells in the date columns might not have dates in them at the time of counting but they might have dates in them at a later stage when the count is done again.

    I don't know how to better explain the problem.

  4. #4
    Forum Contributor kalbasiatka's Avatar
    Join Date
    02-27-2016
    Location
    Brest, Belarus
    MS-Off Ver
    2021
    Posts
    224

    Re: VBA - Counting unique values based on mutiple columns

    Quote Originally Posted by Bezzie View Post
    I don't know how to better explain the problem.
    You don't have to invent anything, I already wrote that it is necessary.
    A file with a table and on a separate sheet that should look like the result.
    If the file contains personal information, delete it. I have no desire to make a file, but there is a desire to help with the code.

  5. #5
    Forum Contributor
    Join Date
    12-06-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    201

    Re: VBA - Counting unique values based on mutiple columns

    Attached is a file with data similar to what I have.

    There is no output sheet of what the answer should look like.

    All I want is to do the count of unique values in col C in VBA code where the date in any of the date columns = 18-Jan-16 and get an answer of 3.

    The three unique shares is BB, FE, GE.
    Attached Files Attached Files

  6. #6
    Forum Contributor kalbasiatka's Avatar
    Join Date
    02-27-2016
    Location
    Brest, Belarus
    MS-Off Ver
    2021
    Posts
    224

    Re: VBA - Counting unique values based on mutiple columns

    Made specifically for your example. How will be the data in the real file I don't know and don't guarantee uptime. Will edit themselves.
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    12-06-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    201

    Re: VBA - Counting unique values based on mutiple columns

    Hi kalbasiatka

    Looks good. I'm going to try it in my code.

    Thank you

  8. #8
    Forum Contributor
    Join Date
    12-06-2012
    Location
    South Africa
    MS-Off Ver
    Excel 2010
    Posts
    201

    Re: VBA - Counting unique values based on mutiple columns

    Hi kalbasiatka

    Made a few adjustments to work with my ranges and so far it is working like a charm. Thank you very much again.

+ 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. [SOLVED] Need Help Counting Unique Values If 2 Columns Match
    By Xeba37 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-10-2016, 05:29 AM
  2. [SOLVED] counting unique values into tw odifferent columns
    By joannelittell in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-10-2013, 10:15 AM
  3. [SOLVED] Counting Unique Values Across 2 Columns
    By mrfloopa in forum Excel General
    Replies: 3
    Last Post: 06-12-2012, 02:38 PM
  4. Counting Unique Values based on several criteria
    By GowHow in forum Excel General
    Replies: 2
    Last Post: 04-25-2012, 10:16 PM
  5. Replies: 0
    Last Post: 03-08-2012, 12:18 PM
  6. Replies: 6
    Last Post: 10-18-2011, 07:34 PM
  7. Replies: 2
    Last Post: 02-10-2005, 10:06 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