+ Reply to Thread
Results 1 to 5 of 5

How to change cell reference for countif formula for every nth row

  1. #1
    Registered User
    Join Date
    03-26-2021
    Location
    Paris
    MS-Off Ver
    Office 365
    Posts
    8

    How to change cell reference for countif formula for every nth row

    Hello, my question is regarding changing cell reference for every 5th row.

    My formula in use is as such,

    From Cell E2 to E5
    IF(COUNTIF(D$2:D$5,"2")>=3,"Active",IF(AND(COUNTIF(D$2:D$5,"2")>=1,COUNTIF(D$2:D$5,"2")<3),"Rarely active","Inactive"))

    But from Cell E6 to E9 I need the formula to change cell reference. So the formula should become
    IF(COUNTIF(D$6:D$9,"2")>=3,"Active",IF(AND(COUNTIF(D$6:D$9,"2")>=1,COUNTIF(D$6:D$9,"2")<3),"Rarely active","Inactive"))

    And this goes for about 10k rows. Therefore I need a quicker way to make the cell reference change. Please help me!

    Thanks ExcelForum fam!
    Last edited by Abis; 06-02-2021 at 05:52 AM.

  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,753

    Re: How to change cell reference for countif formula for every nth row

    Instead of D$2:D$5 in your formula, you can use this in the formula in E2:

    INDEX(D:D,INT((ROWS($1:1)-1)/4)*4+2):INDEX(D:D,INT((ROWS($1:1)-1)/4)*4+5)

    You will need to make the substitution 3 times, and then you can copy the formula down as required.

    Hope this helps.

    Pete

  3. #3
    Registered User
    Join Date
    03-26-2021
    Location
    Paris
    MS-Off Ver
    Office 365
    Posts
    8

    Re: How to change cell reference for countif formula for every nth row

    Hey Pete,
    The formula works like magic!! Thanks a lot.

    I am new to excel and do not understand INDEX and INT function. If possible could you please briefly explain it?

    P.S It is not urgent and is not of priority! Only if you can

    Thanks again!!

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

    Re: How to change cell reference for countif formula for every nth row

    Glad to help, Abis, and thanks for the rep.

    You will notice that the formula is of the type:

    =INDEX(...) : INDEX( ... )

    and so basically the first INDEX will return the first cell reference and the second INDEX the final cell reference in column D. The bit that changes is the row reference, in that the first one adds 2 to the calculation given by the INT term and the second one adds 5 to that calculation. To understand what the INT term is doing, you can put this in a blank cell somewhere:

    =INT((ROWS($1:1)-1)/4)*4+2

    and copy this down a few rows. You will see that it returns 2 on the first few rows, then 6 for the next few, then 10, and so on. The ROWS($1:1) term initially returns 1 (i.e. the number of rows between the two references), but notice that the first reference is anchored to row 1, so when this is copied down it becomes ROWS($1:2) (which returns 2), then ROWS($1:3) (returning 3), then ROWS($1:4) and so on, on successive rows, and so basically it generates a sequential number for each row. 1 is subtracted from this (giving a sequence 0, 1, 2, 3, 4, 5, etc.), and then that is divided by 4 within the INT function (which returns the integer, or whole number, part). This, then gives rise to a sequence 0, 0, 0, 0, 1, 1, etc., which is then multiplied by 4 and has 2 added on, which gives the sequence 2, 2, 2, 2, 6, 6, 6, 6, 10, 10, and so on. and these are the initial cell references that you want. The other term operates in a similar way, but generates the sequence 5, 5, 5, 5, 9, 9, 9, etc., which corresponds to the second cell reference that you want.

    Hope this helps.

    Pete

  5. #5
    Registered User
    Join Date
    03-26-2021
    Location
    Paris
    MS-Off Ver
    Office 365
    Posts
    8

    Re: How to change cell reference for countif formula for every nth row

    Thanks again Pete!! This helps a lot.

    Cheers,

    Abis

+ 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. Copy formula across cells not changing cell reference COUNTIF
    By rj16184 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-08-2018, 05:55 AM
  2. [SOLVED] Cell reference in a countif formula
    By Losguapos1 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 01-20-2018, 07:11 PM
  3. Reference a dynmaic range from one cell into a countif formula
    By jdoerr1021 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-06-2017, 07:46 PM
  4. Replies: 1
    Last Post: 02-11-2015, 01:56 PM
  5. [SOLVED] countif formula changes cell values and cell reference is unchanged
    By KK1234 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-24-2014, 11:37 AM
  6. COUNTIF formula with reference to cell above
    By pri31 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-02-2013, 08:07 AM
  7. Dragging formula, change sheet reference, but not cell reference
    By Kalilaya0419 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-13-2013, 04:50 PM

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