Count all fields in an column, except for n specified range - excel

I am trying to count all the field in an entire column except for n specified range. I need to select the entire column to cater for future expansion
currently i am trying:
=COUNTIF(B:B,"<>ASY999 OR <>ASY002 OR <>CIB001 OR <>""")
But the formula still counts the blank cell at the bottom of the column I get a return value of 65536 which is not correct

Which version of Excel? In Excel 2007 or later try COUNTIFS (with an "S"), i.e.
=COUNTIFS(B:B,"<>ASY999",B:B, "<>ASY002",B:B,"<>CIB001",B:B,"<>")
I assume ASY999 etc are text values.....
In Excel 2003 or earlier you can use SUMPRODUCT but you need to restrict the range rather than using the whole column so assuming data in rows 2 to 1000 try
=SUMPRODUCT(ISNA(MATCH(B2:B1000,{"ASY999","ASY002","CIB001"},0))*(B2:B1000<>""))

Related

Get last 5 values ignoring blanks excel

So I have data consisting of the following:
there are multiple more rows.
Im trying to retrieve the last 5 values in a row, for further use.
I can do this with a simple INDEX(MATCH()) setup, however that doesn't ignore the blank cells, which I would like it to do. It does successfully detect the first nonblank cell and returns that, however when it's blank in the middle of the 5 most recent, it doesn't remove that.
something like this is what it does now:
however i want it to come back in this format:
and so on. A blank could occur at any position, and there may not always be 5 scores available to retrieve.
TIA
You could use the following array-formula (entered with ctrl+shift+enter in older Excel versions):
=INDEX(1:1,AGGREGATE(14,6,COLUMN(A:G)/(A1:G1<>""),{5,4,3,2,1})) copied down.
Aggregate creates an array of the column numbers divided by 1 or 0 (TRUE or FALSE). Divided by 0 results in an error and gets ignored. It then takes the 5th largest to the largest column number without error and returns that as an array on the indexed row.
Where 1:1 represents the first row and A:G represents the first to last column used.
If you would want it on row 2 and column A:Z you'd have to amend it like this:
=INDEX(2:2,AGGREGATE(14,6,COLUMN(A:Z)/(A2:Z2<>""),{5,4,3,2,1}))
Different approach - using the new Excel 365 formulas:
This will return the values of the last five non-empty cells of row 2
=LET(
data,FILTER(B2:H2,B2:H2<>""),
cntData,COUNT(data),
matrix,SEQUENCE(1,MIN(cntData,5),IF(cntData>5,cntData-4,1)),
INDEX(data,1,matrix)
)
data returns all values except empty cells using the FILTER- formula
cntData holds the number of cells
using SEQUENCE a matrix is build that will return the column-indices to be returned. In case less then 5 values are available, the matrix returns 1 to cntData.
finally this "index-matrix" is used to return the values from the filtered data
This could be enhanced, by storing the number of cells to be returned within a named cell - and referencing this name in the formula. By that you could easily alter the number without altering the formula.

Return non-blank rows from a range in a new range list in Excel

Using Excel, assumed there is a range of data including text and number values. But some are blank rows. How could I create a range of list which only includes non-blank rows using Excel functions? Thus, I don't have to copy, paste and remove blank rows by daily.
For example, Raw data table as below,
AAA 111 111 111 111
BBB 111 111 111 111
AAA 111 111 111 111
CCC 111 111 111 111
QQQ 111 111 111 111
SSS 111 111 111 111
BBB 111 111 111 111
Then, create a new range of table like this,
AAA 111 111 111 111
BBB 111 111 111 111
AAA 111 111 111 111
CCC 111 111 111 111
QQQ 111 111 111 111
SSS 111 111 111 111
BBB 111 111 111 111
I was trying to use this formula. However, it doesn't work...
{=IFERROR(INDEX($A$1:$E$12,SMALL(IF($A$1:$E$12<>"",ROW($A$1:$E$12)),ROW(F1:J1))),"")}
{=IFERROR(INDEX($A$1:$E$12,SMALL(IF($A$1:$E$12<>"",ROW($A$1:$E$12)),ROW(F2:J2))),"")}
{=IFERROR(INDEX($A$1:$E$12,SMALL(IF($A$1:$E$12<>"",ROW($A$1:$E$12)),ROW(F3:J3))),"")}
{=IFERROR(INDEX($A$1:$E$12,SMALL(IF($A$1:$E$12<>"",ROW($A$1:$E$12)),ROW(F4:J4))),"")}
{=IFERROR(INDEX($A$1:$E$12,SMALL(IF($A$1:$E$12<>"",ROW($A$1:$E$12)),ROW(F5:J5))),"")}
{=IFERROR(INDEX($A$1:$E$12,SMALL(IF($A$1:$E$12<>"",ROW($A$1:$E$12)),ROW(F6:J6))),"")}
{=IFERROR(INDEX($A$1:$E$12,SMALL(IF($A$1:$E$12<>"",ROW($A$1:$E$12)),ROW(F7:J7))),"")}
IF($A$1:$E$12<>"",ROW($A$1:$E$12)) in array context will result in a row vector {1,1,1,1,1} in case of row 1. So it always results in 5 times either the row number or FALSE for each row. So you will get each not empty row number 5 times.
One option would be only checking if column A is empty and having the array formula for each single cell instead of the single rows:
{=INDEX($A$1:$E$20,SMALL(IF($A$1:$A$20<>"",ROW($A$1:$A$20)),ROW(1:1)),COLUMN(A:A))}
Example:
Of course this is really not performant for big ranges. But I don't see another possibility using formulas.
What I would do is having a helper column using the array formula:
{=AND(A1:E1<>"")}
for each row.
And then sorting the table by this helper column descending.

IF Values match return true

I am trying to get some code working but when I change a target cell into a range of cells I get an error #VALUE!
this code works
=IF(AND(A1=Sheet2!A2,B1=Sheet2!B2),"TRUE","FALSE")
but if I add a range I get #VALUE! Error
=IF(AND(A1=Sheet2!A2:A10,B1=Sheet2!B2:B10),"TRUE","FALSE")
Update : Here is an example of what I am trying to achieve
Any help would be much appreciated
Many Thanks,
And
Different approach from your logic statement. Instead it looks through your table and match the name with the row and the column with the date selected and the pulls the value at that location.
=INDEX($B$7:$G$8,MATCH($B3,$A$7:$A$8,0),MATCH(C$1,$B$6:$G$6,0))
IMPORTANT: The names in you B3:B4 area have to be unique and spelled identical to your A7:A8 area. That included trailing or leading spaces that you may accidentally drop in.
Adjust reference ranges to match your need if tables are on different sheets of your workbook.
THIS IS AN ARRAY FORMULA - Hit Ctrl+Shift+Enter While still in the formula bar
=INDEX(B2:B10,SMALL(IF(A2:A10=A1,IF(B2:B10="ONCALL",ROW(A2:A10)-1)),1))
=INDEX(B2:B10, - Look through B2:B10 and return the row number calulcaulated by:
SMALL(IF(A2:A10=A1,
IF(B2:B10="ONCALL",
ROW(A2:A10)-1)),1))
This is building an array of row numbers minus 1 where both IF statements are true (Date matches and "ONCALL" present), SMALL then returns the nth value in ascending order - I have asked for the 1st match (or the smallest row number) which INDEX then uses to return the result.

Trying to specify multiple wildcards in a countifs function for Excel

I am working on a data sheet that has almost 300,000 rows by about 40 columns.
I have a countifs function to count the number of rows that have an entry ranging from "A1" through "A5" for each letter A-G in a particular column.
I have broken out analysis on separate sheets to pull data for each row for each separate letter A-G using countifs(range,"other data","F?") (I know its simplified).
I need to create a new sheet that excludes any row with an A value in it.
I tried countifs(range,"other data", range,{"B?","C?","D?","E?","F?","G?"}) and it only returns the count for the outside values (B and G), how do I get Excel to count all of those other values as well? I would like to keep this format because to create the sheets for B-G, I just used the find and replace to replace "A?" with "B?" and so on for the other sheets.
I would like to just replace "B?" with whatever works to count the number of rows that have B-G in that particular column.
You countifs formula, with an array constant for criteria, returns an array of values. But what you want is the SUM of that array. So:
sum(countifs(range,"other data", range,{"B?","C?","D?","E?","F?","G?"}))
Without the sum function, you will only see the value of the first element of that array.
I have a feeling this is the wrong answer, but I'll say it anyway. Why can't you use
=COUNTIFS(Range,"<>A?")
Or are there other possible values that you want to exclude?
In which case you should be able to use this for A
=COUNTIFS(Range,">=B1",Range,"<=G5")
and for B1-B5
=COUNTIFS(Range,">=A1",Range,"<=A5")+COUNTIFS(Range,">=C1",Range,"<=G5")
which can be modified for C, D, E and F
and this for G
=COUNTIFS(Range,">=G1",Range,"<=G5")

Find cells referring to blank cells

What is the best way to find cells whose formulas refer to blank cells in Excel VBA. I'd like to delete any cell that references a blank cell.
More concretely, I have a two sheets: One sheet contains the actual values:
Product Month1 Month2 Month3
Sample1 1 3 5
Sample2 5 7 6
Sample3 3 8 2
The other is a summary view, with formulas to sum up the values, with the following formulas:
Product Month1
=values!A2 =SUM(values!B2:D2)
=values!A3 =SUM(values!B3:D3)
=values!A4 =SUM(values!B4:D4)
=values!A5 =SUM(values!B5:D5)
TOTAL =SUM(values!B:D)
Now in the previous example, the last raw refers to a blank row, namely the fifth row. Excel will show those cells as "0". Is there a mechanism to delete those cells within VBA?
Please note I prefer deleting the rows, to keep the TOTAL row close to the actual last value. Otherwise, the Total row might be distant from the rest of the values. Also, having blank cells with formulas may lead to a large Excel file.
EDIT: Clarified the question to role out the keeping the cells blank.
Is it always the last row, that could evaluate to 0?
If so u Could use a IF statement like:
=IF(SUM(values!B2:D2) > 0 ,values!A2,"") =IF(SUM(values!B2:D2),SUM(values!B2:D2),"")
No VBA needed...
I think Autofilter is the way to go here. If there's a zero in column A, I'm guessing you want to hide that whole row. You say delete, but I wonder if hide is a better way.
Put a filter on the range and for column A select everything except 0.
You could do this without having to write code to delete rows. I would use a variant of Arnoldiuss' solution.
For the Month total use:
=IF(LEN(values!A2)>0,SUM(B2:D2),"")
In this way, you can simply fill-down all the formulas and not have to worry if you reference a non-existent product.
Based on your edit i guess a pivot table fits your needs.
Add the products to the rowlabels and add the following calculated field to the values
=SUM(Month1,Month2,Month3)
Then add a value filter > 0
I would not recommend deleting rows in the "formula worksheet", for future use the series would wrecked, because of the missing references.

Resources