+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    11-03-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    2

    Smile Count columns using just a formula

    Hi there!

    I've got an Excel book containing only on worksheet. In that sheet I've arranged the results of our servers' backup using one colum for each server in our company, and one row for each day of the year. I've attached a dummy version.

    Every cell contains the result of each server backup for that day: Failed or OK.

    I want to use a formula (I mean, not with VBA) to count how many servers failed to backup, that is, how many columns have some cell with content = "Failed".

    I could do that by creating a new last row (the checking row) in which each cell checks if its colum has some "Failed" values, and then summing those cells to add up how many columns has failed. However, with this method, if I'd insert a new colum (i.e., add a new server) I'd have to extend the formula to the new cell in the checking row.

    What I really want is some kind of smart formula (array formula or alike) that will adapt to inserting/deleting new columns (i.e., adding new servers or removing old ones) without having to change anything in the book.

    Is that possible without using VBA?

    Thank you.
    Attached Files Attached Files

  2. #2
    Forum Moderator daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2007
    Posts
    9,506

    Re: Count columns using just a formula

    Here's one possible solution.....

    =SUM((MMULT(TRANSPOSE((B2:D11="Failed")+0),ROW(B2:D11)^0)>0)+0)

    confirmed with CTRL+SHIFT+ENTER

  3. #3
    Forum Moderator teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    2003 & 2010
    Posts
    10,042

    Re: Count columns using just a formula

    However, with this method, if I'd insert a new colum (i.e., add a new server) I'd have to extend the formula to the new cell in the checking row.
    not necessarily. Attached see a worksheet where the formula extends on column beyond the last server column. As a visual reminder, you see a gray column. As long as you insert new servers before the gray column, you won't have to update the formula that calculates the total number of servers that have failed (B14).

    Same principle is applied to the current row 13. If you insert new rows above row 12, the formulas will adjust the range automatically, because the formulas extend into the grayed row.

    This way you can avoid complicated array formulae.
    Attached Files Attached Files
    teylyn
    Microsoft MVP - Excel
    At Excelforum, you can say "Thank you!" by clicking the icon below the post.

    Avoid pie charts with more than two data points. Why? See here (pdf, 559 kb). The only acceptable pie chart is here.

  4. #4
    Registered User
    Join Date
    11-03-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Count columns using just a formula

    WOW!

    That's exactly what I wanted daddylonglegs! I don't understand how it works, but it does. However, I'm not giving up! I'll discover how that crazy formula does its magic, no matter how long it takes me.

    Thank you very much!

    teylyn, thanks a lot anyway. I really appreciate your time and effort too, but daddylonglegs' solution is closer to what I was looking for.

  5. #5
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,379

    Re: Count columns using just a formula

    I would say you could probably extend dll's formula by means of a Dynamic Named Range - ie instead of using a hard reference create a name as below

    Code:
    Name: _ServerData
    RefersTo: =INDEX($1:$65536,2,2):INDEX($1:$65536,MATCH(9.99999999999999E+307,$A:$A),MATCH(REPT("Z",255),$1:$1))
    Assumes Server Names are text strings and that dates are numerical -- no numbers are entered below last date in column A.

    As you add dates, insert columns etc the DNR will adapt accordingly and you should on that basis find you can use the below without ever needing to adjust for new ranges etc...
    (and whilst only ever looking at the necessary cells)

    Code:
    =SUM((MMULT(TRANSPOSE((_ServerData="Failed")+0),ROW(_ServerData)^0)>0)+0)
    confirmed with CTRL + SHIFT + ENTER
    As I say, just a suggestion...

Thread Information

Users Browsing this Thread

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

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.2.0