+ Reply to Thread
Results 1 to 8 of 8

Counting Cells with Variable Reference

  1. #1
    Registered User
    Join Date
    04-08-2009
    Location
    NY
    MS-Off Ver
    Excel 2007
    Posts
    3

    Counting Cells with Variable Reference

    Hi...I've been working on this problem for awhile and have been unable to figure out a solution. I have a list of data that is generated daily on one sheet, on a second sheet I have a list of customers and the total number of product received from them.

    What I am looking for is a way for the formula to automatically count the raw data based on the Total In count listed next to the customers name.

    The raw data is generated daily and the customer names, counts, and number of customers vary each day.

    I have been using the following formula as an example: "=IF(B2=0,0,COUNTIFS(INDIRECT("'RAW DATA'!A2:A52"),">2000000",INDIRECT("'RAW DATA'!A2:A52"),"<3000000"))"

    However for each customer I have to go in and change the cell references. Is there some way where the formula can automatically count cells based on the value in another cell or combination of cells?

    I've attached a sample workbook as an example.

    Thanks for any help!

    -yen
    Attached Files Attached Files

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Counting Cells with Variable Reference

    I noticed you're using INDIRECT - are you physically removing and inserting the Raw Data sheet each day ?

  3. #3
    Registered User
    Join Date
    04-08-2009
    Location
    NY
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Counting Cells with Variable Reference

    Yes, in a way. In the actual workbook there is a sheet where you change the date and or time and the data on the raw data sheet will automatically change. This data is polled from a bar code scanner and stored in a external data source. I've attached a picture of the screen that the date and time are changed via.

    I also noticed I posted this with the wrong window to an incorrect forum so please feel free to move to the appropriate section (Excel General)

    Thanks.

    -yen
    Attached Images Attached Images

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Counting Cells with Variable Reference

    Having looked at your file ... if you insert a column between B & C (so old C becomes D and new C is blank) you can keep things simple... eg

    Please Login or Register  to view this content.
    The above can be applied across matrix D2:G11

    Hope that helps

    (Thread moved to Worksheet Functions Forum)
    Last edited by DonkeyOte; 10-29-2009 at 02:46 PM.

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Counting Cells with Variable Reference

    My point re: INDIRECT is that if you're not deleting the sheet itself you don't need to use INDIRECT (it is a Volatile function)

    A non-volatile version of that in the prior post would be:

    Please Login or Register  to view this content.
    Last edited by DonkeyOte; 10-29-2009 at 02:46 PM.

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Counting Cells with Variable Reference

    yensid, apologies, but there was a typo in the prior example - the first INDEX should use 2+SUM(B$1:B1) rather than 1+SUM(B$1:B1) -- this is to account for first row of data being in row 2 rather than row 1. I have modified the prior examples accordingly.

  7. #7
    Registered User
    Join Date
    04-08-2009
    Location
    NY
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Counting Cells with Variable Reference

    Donkey:

    Thanks so much it works like a charm...two months of tinkering around solved in 30 minutes ;o)

    I understand the countif and index functions, but have never used 2+SUM or "<"&IF before...Is it possible for you to give me a quick explanation for them? Or if there is an online explanation point me in the proper direction?

    Thanks.

    -yen

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Counting Cells with Variable Reference

    In essence we're simply using a standard COUNTIF and a COUNTIF as you know works along the lines of:

    Please Login or Register  to view this content.
    In our case our formula (for D2) looks like

    Please Login or Register  to view this content.
    So you can see (by means of colour coding) that we use 2 INDEX functions to create the range and a subsequent IF in conjunction with & and < operator to create the criteria
    (the last bit in Italics which sits outside of the COUNTIF is to ensure we're displaying only "periodic" movement - inappropriate term here in truth but one that epitomises the general principle)

    So - range - in more detail...

    Please Login or Register  to view this content.
    You can see the INDEX calls are separated by a colon indicating we're using INDEX in this context to create range references - this may be different to how you've seen it used before ?

    INDEX is a pretty flexible formula, eg:

    Please Login or Register  to view this content.
    could be used to return contents of A10 or

    Please Login or Register  to view this content.
    could be used to create a range A10:A20

    make sense ?

    In your case the start row & end row for the range is determined by the rolling sum of the values in Column B, for ex. B2 = 51 ... this figure states we should look only at the first 51 rows of data in the table... we know first row of data is row 2.

    So to establish starting cell we have:

    Please Login or Register  to view this content.
    which says column is A and row is to be 2 + sum of prior values (ie excluding current row) in B which for row 2 will be 0 given B1 is non-numeric

    To establish end row we have:

    Please Login or Register  to view this content.
    which says column is A and row is to be 1 + sum of all values in B up to and including the current row which for row 2 will be 52 (1+51)

    Thus we end up in essence with a range that says

    Please Login or Register  to view this content.
    When we move to the next row down in our records the start row & end row will update accordingly, eg:

    B2: 51
    B3: 168
    So our start range for the COUNTIF in row 3 of our results table will be:

    Please Login or Register  to view this content.
    And end row

    Please Login or Register  to view this content.
    Does that make sense ?

    The criteria for the COUNTIF we set to be the value in row 1 in the column to the right of the cell containing the formula (ie less than next boundary), however, when it comes to the last column we have a problem given there is no limit in the next cell - to account for this we use the IF

    Please Login or Register  to view this content.
    so we say if the value in row 1 of the column to the right is non-numeric use 5000000 else use the value in row 1 of the column to the right.

    to get this into a readable string we concatenate the "<" operator with this value by means of & ....

    Please Login or Register  to view this content.
    Obviously this means in each column we're counting how many records are less than the limit ... but this will obviously include values that may be included in prior boundaries so we need to subtract the prior totals from the COUNTIF total

    Please Login or Register  to view this content.
    Last edited by DonkeyOte; 10-31-2009 at 04:00 AM.

+ 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