+ Reply to Thread
Results 1 to 2 of 2

COUNTIF - The End Range Varies

  1. #1
    Registered User
    Join Date
    06-08-2009
    Location
    Michigan
    MS-Off Ver
    Microsoft 365 Apps for enterprise
    Posts
    29

    COUNTIF - The End Range Varies

    Hello all,
    I use Microsoft 365 Excel

    I have a column with fruit names and I know what the fruit names are.
    I need a count for each fruit.
    So, if I use the whole column A, then a COUNTIF function will work just fine, =COUNTIF(A:A,"Orange").

    The challenge is B1 has the last row to be used in the count.
    In other words, the range of cells for COUNTIF will be A1:A(whatever in B1)

    For example: The preceding number below shows the row number in Col A.
    1 Orange
    2 Apple
    3 Apple
    4 Banana
    5 Orange
    6 Strawberry
    7 Orange
    8 Apple

    So,
    If B1 is 6, then the COUNTIF range is A1:A6 and the Orange count is 2
    If B1 is 7, then the COUNTIF range is A1:A7 and the Orange count is 3

    How do I write the COUNTIF range to accommodate the end range being a variable?
    Or, maybe there is a different formula that will do the trick?

    Thank you for any help.

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,728

    Re: COUNTIF - The End Range Varies

    Use this instead:

    =COUNTIF(A$1:INDEX(A:A,$B$1),"Orange")

    although the COUNTIF function is intelligent enough to only use the used-range, so there is no particular advantage in doing this.

    Hope this helps.

    Pete

+ 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. How to sum a range in a colum that varies
    By nekovolta in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-27-2019, 07:22 AM
  2. Replies: 1
    Last Post: 01-12-2019, 03:36 PM
  3. COUNTIF where number of cells to be counted varies
    By nicandthat in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-27-2017, 04:45 PM
  4. VBA URL In Range varies and can be any number of row
    By maria.blue44 in forum Excel Programming / VBA / Macros
    Replies: 27
    Last Post: 06-04-2013, 12:53 AM
  5. Getting activesheet.range to refer to a name that varies...
    By karen000 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-01-2009, 12:05 PM
  6. Insert SUM Formula using VBA (Range Varies)
    By William Horton in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-08-2005, 11:05 AM
  7. Setting a range that varies
    By Stephen English in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-11-2005, 06:06 PM

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