+ Reply to Thread
Results 1 to 29 of 29

Function to count number of rows and insert a value

Hybrid View

  1. #1
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Function to count number of rows and insert a value

    Try instead, then:
    =IF(COUNTIF($C$2:C2,"="&$G$2)<$G$3,IF(OR($G$4=1,MOD(ROW()-1,$G$4)=1),$G$2,""),"")
    note, I also changed Row(A2) to Row()-1... same in this case...

    This part:

    COUNTIF($C$2:C2,"="&$G$2) counts how many times from the top of the column to the the row before the current row contain the dosage amount... this is to determine if you have hit the number of dosages allowed by the value in G3.. if the limit has been reached, then a blank is returned...

    If the number of dosages counted is less than your value in G3, then the next part takes over.. OR($G$4=1,MOD(ROW()-1,$G$4)=1

    the Mod() function returns the remainder when arg 1 is divided by arg 2... so the only time that is 1 is when the row() number divided by the value in G4 gives a remainder of 1. e.g. if you are in in Row 5 and your interval is set to 3, then Row()-1 gives 4 and 4 divided by 3 is 1 with remainder 1.. same if you are in Row 8, then Row()-1 is 7 and 7 divided by 3 is 2 remainder 1...and so on...
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  2. #2
    Registered User
    Join Date
    06-16-2009
    Location
    Pretoria, South Africa
    MS-Off Ver
    Excel 2003
    Posts
    30

    Re: Function to count number of rows and insert a value

    Quote Originally Posted by NBVC View Post
    Try instead, then:
    =IF(COUNTIF($C$2:C2,"="&$G$2)<$G$3,IF(OR($G$4=1,MOD(ROW()-1,$G$4)=1),$G$2,""),"")
    note, I also changed Row(A2) to Row()-1... same in this case...

    This part:

    COUNTIF($C$2:C2,"="&$G$2) counts how many times from the top of the column to the the row before the current row contain the dosage amount... this is to determine if you have hit the number of dosages allowed by the value in G3.. if the limit has been reached, then a blank is returned...

    If the number of dosages counted is less than your value in G3, then the next part takes over.. OR($G$4=1,MOD(ROW()-1,$G$4)=1

    the Mod() function returns the remainder when arg 1 is divided by arg 2... so the only time that is 1 is when the row() number divided by the value in G4 gives a remainder of 1. e.g. if you are in in Row 5 and your interval is set to 3, then Row()-1 gives 4 and 4 divided by 3 is 1 with remainder 1.. same if you are in Row 8, then Row()-1 is 7 and 7 divided by 3 is 2 remainder 1...and so on...

    Thanks-much appreciated. I'll have to play with formulas as I haven't worked with mod and row functions before.

    Appreciate the help-works great

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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