+ Reply to Thread
Results 1 to 9 of 9

how to use CountIf with Offset for values in Range, last n rows

  1. #1
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    271

    how to use CountIf with Offset for values in Range, last n rows

    Hello Seniors

    Background
    1) Rows 1 to 11 should remain static and not be disturbed.
    2) Data range starts from B12 and keeps expanding IN Column B
    3) Cell B4 finds the last value appearing in Data range B12:B5000 (assumed, max data rows could exapnd upto 5000)
    4) Cell A7 is controller which indicates how many rows up from last cell (Bottom) presently, B35, it should look up

    What is required / Help re
    5) Formula needed in B6 to find how many times B4 value in previous rows [Controller A7 ] occurs,
    6) For understanding purpose, Yello cells are manually highlighted for evaluation purpose i.e. 20 = A7

    So, Result in Cell B6 should be 12. What is 12 is ...12 times, data in range B15:B34 occured, that is, last 20 rows (referred in A7) , were less than value of last cell shown in B6

    Sample workbook (MS-Excel 2010 version) attached.
    I am unable to figure it out how to get this as data keeps on expanding, and similar data would be there in adjoining columns on right.

    Simple soultion (assuming data range would have remained static, and no need to lookback how many [n] rows up from last cell, result could have easily been achieved using formula
    Please Login or Register  to view this content.
    given in cell B9 currently.
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    11-02-2020
    Location
    Paris, France
    MS-Off Ver
    Professional Plus 2013
    Posts
    41

    Re: how to use CountIf with Offset for values in Range, last n rows

    Hi analystbank,

    I ain't sure I got exactly what you asked for.
    But if you want to limit yourself to a certain amount of data, you could try :
    Please Login or Register  to view this content.
    That would produce 12, the same way would
    Please Login or Register  to view this content.
    then you were on the right track with
    Please Login or Register  to view this content.
    It would give you the last value. To return the last row number, you just need to modify it slightly into :
    Please Login or Register  to view this content.
    I subtracted the 15 first rows you aren't counting apparently. Adjust to your likings.

    If it's not quite what you were looking for, please bear with me.
    Also why save in .xlsm, I didn't see any macro in there?
    Attached Files Attached Files
    ⭹ If this helped you, please add reputation

  3. #3
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    271

    Re: how to use CountIf with Offset for values in Range, last n rows

    Thanks for feedback, I am checking, how to combine formulas to get result you have given in Cell C6.

    In my ever expanding work, i would not know, if it always starts with B15, that is why I have added a controller in Cell A7 which should count back from last cell in Column B and move n rows up and consider it as range and do the arithmatic. I guess, some loopholes in above.

    Sorry, but it wont be flexible to my requirement.

    File is in xlsm becuase it has Macros in my main workbook.
    Last edited by analystbank; 12-23-2020 at 07:46 AM.

  4. #4
    Registered User
    Join Date
    11-02-2020
    Location
    Paris, France
    MS-Off Ver
    Professional Plus 2013
    Posts
    41

    Re: how to use CountIf with Offset for values in Range, last n rows

    Hi.

    Are you saying you want to define how many values are below the last value entered in column B in the range between last value minus 1 and last value minus n ?
    And to set n you simply enter it in A7?

    I was under the impression there was a calculation need to get to this n.

    If so you could then try a variant in C6 :
    Please Login or Register  to view this content.
    where this part gives you the last row number (35)
    Please Login or Register  to view this content.
    So until I understand how you get the 20, you can just refer to your A7 cell instead of mu calculated B7 one.

    Cheers
    Attached Files Attached Files
    Last edited by Exl-Noob; 12-23-2020 at 08:16 AM.

  5. #5
    Forum Expert BMV's Avatar
    Join Date
    01-13-2020
    Location
    St-Petersburg, Russia
    MS-Off Ver
    2013-2016
    Posts
    1,329

    Re: how to use CountIf with Offset for values in Range, last n rows

    non volatile
    =countif(index(b:b;lookup(2;1/(b12:b5000<>0);row(b12:b5000))-1):index(b:b;max(12;lookup(2;1/(b12:b5000<>0);row(b12:b5000))-A7-1));"<"&b4)
    Attached Files Attached Files
    Last edited by BMV; 12-23-2020 at 08:17 AM.

  6. #6
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: how to use CountIf with Offset for values in Range, last n rows

    Please try

    =COUNTIFS(INDEX(B12:B5000,MATCH(9^9,B12:B5000)-A7):B5000,"<"&B4)
    Attached Files Attached Files

  7. #7
    Valued Forum Contributor
    Join Date
    04-27-2015
    Location
    Abu Dhabi, U.A.E
    MS-Off Ver
    Office 365 | 2016
    Posts
    696

    Re: how to use CountIf with Offset for values in Range, last n rows

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    08-17-2013
    Location
    Asia
    MS-Off Ver
    Excel 2021
    Posts
    271

    Re: how to use CountIf with Offset for values in Range, last n rows

    Many thanks to all

    @BMV
    Excel 2010 find error in formula and suggest to use Insert Function to fix problem

    @Bo_Ry
    suggested solution, works well. I am moving on with my work , keep this suggestion, as it also has alternate way to find MIN, MAX etc and appears to be flexible to my work requirements.

    @Shareez
    suggested solution, works well, I just changed
    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    not sure, what -21 does and should i link to some cell or leave as it is.

    My Controller in A7 may change to modify/change the range criteria.
    Last edited by analystbank; 12-24-2020 at 03:22 AM.

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,830

    Re: how to use CountIf with Offset for values in Range, last n rows

    Try this:

    =sumproduct(--(offset($b$12,counta(b12:b5000)-(A7+1),,A7)<b4))
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

+ 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. Populate Countif values (Offset) into Array and loop through it
    By mchilapur in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-16-2017, 05:55 AM
  2. [SOLVED] Dynamic Range With Countif and Offset
    By James Swallow in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-09-2016, 09:52 AM
  3. Offset and Countif with dynamic Range
    By JKK123 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-22-2013, 12:15 AM
  4. Using countif and offset for a named range
    By smithwa1963 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-22-2012, 03:04 PM
  5. Replies: 3
    Last Post: 07-07-2011, 10:03 PM
  6. Dynamic Range using Offset and CountIF
    By mark_jam3s in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-04-2008, 11:43 AM
  7. Offset, Dynamic range, Countif
    By Bryce in forum Excel General
    Replies: 3
    Last Post: 10-26-2005, 08:05 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