+ Reply to Thread
Results 1 to 8 of 8

CountIF VBA Arrays

  1. #1
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    CountIF VBA Arrays

    I have coded a spreadsheet wherein the user enters data through InputBoxes. It's looped to repeat as many times as necessary. The data is an array in memory. I now need to do a CountIf for one of the values within the array that meets 2 criteria. I have tried the following two ways, neither work.

    Object Error:
    Please Login or Register  to view this content.
    AND

    Doesn't recognize the "range"
    Please Login or Register  to view this content.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: CountIF VBA Arrays

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: CountIF VBA Arrays

    well I feel stupid now.

    That worked. I realized where I wanted it in the process and used a loop to get what I needed.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: CountIF VBA Arrays

    You can apply sumproduct to an array, but not countif -- it requires a range.

  5. #5
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: CountIF VBA Arrays

    I needed a counter of sorts but the places I put them that would not always be accurate or affected the step I needed the counter for. Then when you posted the above I realized where I could put it and have it be accurate. Much appreciated.

  6. #6
    Forum Contributor
    Join Date
    07-30-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    476

    Re: CountIF VBA Arrays

    I know this is late, but is this for sure correct, I know countif doesn't work with array in worksheet, also true in VBA array?

  7. #7
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: CountIF VBA Arrays

    @cmore The following code worked. It was placed in a separate FOR/NEXT statement then the other code that I had the calculation steps in. It allowed me to do the count as a separate step but maintin the accuracy of the calculations.

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    07-30-2013
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    476

    Re: CountIF VBA Arrays

    Nice, I used something similar to build a unique array. Good stuff

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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