excel formula with "different" columns - not just a range - excel

I try to do like this:
=COUNTIFS($AA:$AA;$AC:$AC;$AE:$AE;$AG:$AG;$AI:$AI;"yes")<1
Which is of course wrong.
What I would like to do is not use a range (like $AA:$AI) but instead use every second column in the formula source.
Possible or ?

Yes, this is possible with the following formula:
{=SUM(IF(AA:AI="yes";1;0)*IF(MOD(COLUMN(AA:AI);2)=0;1;1))<1}
Note, that this is an array formula. So, you need to press Ctrl + Shift + Enter. For more information on array formula read the following post: https://support.office.com/en-us/article/Guidelines-and-examples-of-array-formulas-7d94a64e-3ff3-4686-9372-ecfd5caa57c7
The above formula counts all the occurrences of the word "yes" in the columns AA through AI. But each occurrence is furthermore multiplied with 1 or 0 depending on whether the column number can be divided by 2 without rest. Example:
Column AA is column 27. 27 divided by 2 equates to 13 with a remainder of 1. So, since there is a remainder, the second portion of the above formula (the second if) will return a 1 and not a 0. Hence, any occurrence of "yes" in column AA is accounted for. At the same time all occurrences in column AB will get multiplied with 0 (not accounted for). Since, I chose to use the divisor 2 all "yes" in every other column will be accounted for.

You can try this:
=COUNTIF(AA:AA,"yes") + COUNTIF(AC:AC,"yes") + COUNTIF(AE:AE,"yes") + COUNTIF(AG:AG,"yes") + COUNTIF(AI:AI,"yes")
See image for reference:

Related

How to make Excel follow a formula algorithm on every 3 rows

I want to make Excel follow a formula pattern on every 3 rows, such that after an increase of three in the conditional if statement, there should be an increment of one on return value "TRUE". So that every time I drag it down, the algorithm gets applied to succeeding 3 rows that it follows. I have this simple formula of:
=IF(B11="RTR",RTR!G11:Z11,IF(B11="DHG2",'DHG2'!G11:Z11,IF(B11="JQV",JQV!G11:Z11,"")))
=IF(B12="RTR",RTR!G11:Z11,IF(B12="DHG2",'DHG2'!G11:Z11,IF(B12="JQV",JQV!G11:Z11,"")))
=IF(B13="RTR",RTR!G11:Z11,IF(B13="DHG2",'DHG2'!G11:Z11,IF(B13="JQV",JQV!G11:Z11,"")))
=IF(B14="RTR",RTR!G12:Z12,IF(B14="DHG2",'DHG2'!G12:Z12,IF(B14="JQV",JQV!G12:Z12,"")))
=IF(B15="RTR",RTR!G12:Z12,IF(B15="DHG2",'DHG2'!G12:Z12,IF(B15="JQV",JQV!G12:Z12,"")))
=IF(B16="RTR",RTR!G12:Z12,IF(B16="DHG2",'DHG2'!G12:Z12,IF(B16="JQV",JQV!G12:Z12,"")))
Following the formula I wanted, it's supposed to be followed by:
=IF(B17="RTR",RTR!G13:Z13,IF(B17="DHG2",'DHG2'!G13:Z13,IF(B17="JQV",JQV!G13:Z13,"")))
I tried dragging down the formula to apply it to below rows but the pattern doesn't follow to what I wanted. Instead, the row below goes into like:
=IF(B17="RTR",RTR!G17:Z17,IF(B17="DHG2",'DHG2'!G17:Z17,IF(B17="JQV",JQV!G17:Z17,"")))
Need a little bit of help here.
Thank you.
Here is a solution that doesn't require helper cells:
This formula will increment by 1 every 3 rows:
=CEILING.MATH(ROW()/3)
If you want the sequence to start on a different row, say row 10, you can just subtract that number - 1 from the ROW(), so for starting on row 10 from 1, subtract 9:
=CEILING.MATH((ROW()-9)/3)
And if you wanted the sequence to start from a different number at a different row, you can just add that number -1 to this whole thing, this example will start at 11 on row 10:
=CEILING.MATH((ROW()-9)/3)+10
EDIT: Much better solution proposed by P.b, you don't need the IFs at all:
=INDIRECT(B11 & "!G" & (CEILING.MATH(ROW()/3)+10) & ":Z" & (CEILING.MATH(ROW()/3)+10))
So, an example which you can expand:
VLOOKUP(A1,INDIRECT("'RTR'!"&"G11:Z11",1),1,0)
Not sure where you increment of 3 occurs as B11 goes to B12 and even the last two B16 goes to B17 and the target range matches the row numbers.
As I have shown you can build the target range so adding the row numbers is trivial now. They can be taken from cells, C1 could be 3, C2 6 etc.
The following could be used (to avoid using (volatile) INDIRECT):
=INDEX(
CHOOSE( MATCH(B11, {"RTR","DHG2","JQV"}, 0),
'RTR'!G:Z, 'DHG2'!G:Z, 'JQV'!G:Z),
INT((ROW()-11)/3)+11,
)
It selects the correct tab by matching the value in B11 to an array mentioning the names of the tabs. It than indexes range G:Z from that tab.
The row number shifts 1 number every 3 rows because of INT((ROW()-11)/3)+11.

Reference cells with no gaps to fill table with gaps

I have included 2 tables below to illustrate my problem.
Table 1
Table 2
I am trying to find a formula that fills rows 140, 143 & 146 (Table 2) from rows 15,16 & 17 (Table 1). There is over 100 so it is quite time consuming to input =B15 etc over and over again.
The offset method e.g. =OFFSET($B$15,(ROW()-1)*3,0) only works when I'm referencing gaps, not trying to fill them.
Essentially, where B140's formula is =B15, B143's will be =B140 + 1 row i.e. B16
Thanks for your help!
If you are trying find value for appropriate month you can use INDEX/MATCH entered as array formula:
=IFERROR(INDEX($B$1:$B$4,MATCH(TRUE,MONTH(A10)=MONTH($A$1:$A$4),0)),"")
Array formula after editing is confirmed by pressing ctrl + shift + enter
Edit
To find by month & year use:
=IFERROR(INDEX($B$1:$B$4,MATCH(1,(MONTH(A10)=MONTH($A$1:$A$4))*(YEAR(A10)=YEAR($A$1:$A$4)),0)),"")
it's also array formula
You can use modulo for this. With the Modulo function, you check if the remainder of the row you're on is divisible by a number (e.g. 3 if you want to copy a value every third row). IF(MOD(ROW(E1);3 = 0)
If that's the case, you can divide by 3 and use for example the Index function to copy the nth value of another location (or another worksheet). If that's not the case, you print "" to get an empty row.
=IF(MOD(ROW(E1);3)=0;INDEX($B$1:$B$4;ROW(E1)/3);"")
If you're working with offsets because the row numbers are not on numbers divisible by three, you could manually offset the rows (and do the same for the division that yields the index row). For example, if you want to have rows 2, 5, 8 etc:
=IF(MOD(ROW(E1)+1;3)=0;INDEX($B$1:$B$4;ROW(E2)+1/3);"")

Find Length=2 cell in a given range

I have these two rows with an image path.
In Columns D-H i have only one cell that his length is 2.
I need to find it and do formulas based on it, and I would prefer not writing 5 times "IF", any quick way to find it?
It's unclear what you're asking but it seems like you're just trying to figure out which column has a string with a length of 2 characters.
If this is the case use this formula (assuming your data starts in row 2 of the columns you mentioned):
=match(2,len(D2:H2),0) However, when you write this hit CTRL + SHIFT + ENTER
Which will give you {=match(2,len(D2:H2),0)} this is an array formula you must carry down. This will give you the relative column of the string with 2 as its length. Relative meaning, if the criteria is met in column D, it will return 1 (instead of 4).
If you want the value, just use an Index match like so, using the same CTRL + SHIFT + ENTER I mentioned earlier.
{=index(D2:H2,match(2,len(D2:H2),0))}
Here's a non-vba, non-CTE/Array formula way to do this:
=SUMPRODUCT((LEN(D1:H1)=2)*COLUMN(D1:H1))
Will spit out the number of the column that has a length of 2. If more than one column fulfills this criteria then you will get back garbage. So don't do that.
You can pop that into Index() to get the value that was hit:
=INDEX(A1:H1, 1, SUMPRODUCT((LEN(D1:H1)=2)*COLUMN(D1:H1)))

Excel - formula to find how many cells to sum of N

I want to know how many cells it take to sum N. Please see following example:
number | cells to sum of 100
100 | 1
50 | 2
20 | 3
25 | 4
15 | 4
90 | 2
10 | 2
See the last column, it find the min number of current cell + previous cells to sum of 100.
Is there a way to do so?
Thanks.
In B2, array formula**:
=IFERROR(1+ROWS(A$2:A2)-MATCH(100,MMULT(TRANSPOSE(A$2:A2),0+(ROW(A$2:A2)>=TRANSPOSE(ROW(A$2:A2)))),-1),"Not Possible")
Copy down as required.
Change the hard-coded threshold value (100 here) as required.
As way of an explanation as to the part:
MMULT(TRANSPOSE(A$2:A2),0+(ROW(A$2:A2)>=TRANSPOSE(ROW(A$2:A2))))
using the data provided and taking the version of the above from B5, i.e.:
MMULT(TRANSPOSE(A$2:A5),0+(ROW(A$2:A5)>=TRANSPOSE(ROW(A$2:A5))))
the first part of which, i.e.:
TRANSPOSE(A$2:A5)
returns:
{100,50,20,25}
and the second part of which, i.e.:
0+(ROW(A$2:A5)>=TRANSPOSE(ROW(A$2:A5)))
resolves to:
0+({2;3;4;5}>=TRANSPOSE({2;3;4;5}))
i.e.:
0+({2;3;4;5}>={2,3,4,5})
which is:
0+{TRUE,FALSE,FALSE,FALSE;TRUE,TRUE,FALSE,FALSE;TRUE,TRUE,TRUE,FALSE;TRUE,TRUE,TRUE,TRUE})
which is:
{1,0,0,0;1,1,0,0;1,1,1,0;1,1,1,1}
An understanding of matrix multiplication will tell us that:
MMULT(TRANSPOSE(A$2:A5),0+(ROW(A$2:A5)>=TRANSPOSE(ROW(A$2:A5))))
which is here:
MMULT({100,50,20,25},{1,0,0,0;1,1,0,0;1,1,1,0;1,1,1,1})
is:
{195,95,45,25}
i.e. an array whose four elements are equivalent to, respectively:
=SUM(A2:A5)
=SUM(A3:A5)
=SUM(A4:A5)
=SUM(A5:A5)
Regards
**Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).
I did the first 3 with an excel formula:
D3>100
C4 is where your numbers start, so C4=100, C5=50 etc.
Formula is on D4, D5, D6 etc
On D4:
=IF(C4>=D3;1;"False")
On D5:
=IF(C5>=D3;1;IF(C5+C4>=D3;2;"Error"))
On D6:
=IF(C6>=D3;1;IF(C6+C5>=D3;2;IF(C6+C5+C4>=D4;3;"Error")))
You can keep doing this, just keep replacing "Error" with an longer/updated version of IF(C6+C5+C4>=D4;3.
I don't know if this is the best way, but this will achieve it.
One way to solve this is to create an NxN matrix of equations instead of just a column. An example picture is provided. Columns E through I are hidden. The last column on the right determines the number required
Theoretically, you can also hard code the equations if the number of rows needed to get to 100 is a known small number. For example, if the number of rows is always four or less, C8 would be =IFS(B8>=100,1,SUM(B7:B8)>=100,2,SUM(B6:B8)>=100,3,SUM(B5:B8)>=100,4). BTW, you'll run into sum boundary problems with this equation on the first, second, and third rows. Therefore, the first row will need to be =if(B8>=100,1,""), the second row would be =IFS(B9>=100,1,SUM(B8:B9)>100,2,TRUE,"") and so on.

Insert a range of numbers in one cell

I have a table in Excel which looks like this:
A B C
Row 1: 2100-2200 2200-2300 2300-2400
I'm using a VLOOKUP formula. I want this formula to find a number e.g. 2152 in the table above.
Cell A1 is supposed to contain numbers from 2100 to 2200.
Is this possible to do in Excel?
I dont know exactly what you want to return, this array formula will return the correct interval in A1:C1:
=INDEX($A$1:$C$1;MATCH(1;(E1>=VALUE(LEFT($A$1:$C$1;4)))*(E1<=VALUE(RIGHT($A$1:$C$1;4)));0))
Numeric value your looking for in E1
Dont forget to Ctrl Shift Enter to enter the formula...
Instead of providing the ranges, you need to provide only the lower bound. I.e. try this data:
A B C
Row 1: 2100 2200 2300
Because it is a horizontal setup, you need to use HLOOKUP (VLOOKUP will check the cells in the first column of a table, HLOOKUP the cells in the first row) - and you need to leave the fourth parameter of HLOOKUP/VLOOKUP blank (or set it to TRUE which is the same as leaving it blank). E.g. if you number 2152is in cell A2, use this formula:
=HLOOKUP(A2,$A$1:$C$1,1)
and you'll get 2100.
If you want to have the full range returned, you should use the MATCH function instead:
=INDEX($A$1:$C$1,MATCH(A2,$A$1:$C$1))&"-"&INDEX($A$1:$C$1,MATCH(A2,$A$1:$C$1)+1)
This will return 2100-2200
use lower range of your numbers
A B C D
Lower range 2100 2200 2300 2400
Ranking 1 2 3 4
You want to find a number or ranking corresponding to say 2350
Formula: = HLOOKUP(2350,range (range of your values),2,TRUE)
your range includes 2100 -2400 plus 1-4.
the value 2 in the formula indicates the row that you want result returned from - in this case you want ranking - where 2350 will return a 4; change this number to 1 to return exact value.
sample formula:
= HLOOKUP(O65,J74:N75,2,TRUE)
As OP wants to apply HLookUp to numeric range strings ("2100-2200", "2200-2300", etc.), I suggest the following steps:
reconstruct the range contents to their starting values (2100,2200,2300) isolated via Find searching till the - delimiter) by VALUE(LEFT(A1:C1,FIND("-",A1:C1)-1))
define a named search cell MySrch (example value of 2151 due to OP) and apply HLookUp on the above values to get the lower boundary (here: 2100),
Match the found lower boundary (e.g. 2100) plus character "-" and a * wild card to find the ordinal column position (here: 1st column),
return the found range text (e.g. 2100-2200) via Index(A1:C1,1,{column number}) referring to row 1 and the column position as result:
=INDEX(A1:C1,1,MATCH(HLOOKUP(MySrch,VALUE(LEFT(A1:C1,FIND("-",A1:C1)-1)),1)&"-*",A1:C1,0))
Note that it would be necessary to exclude search values outside the given range boundaries either by formula extension (e.g. If(MySrch>...,"?",{above formula}) or to add a last range defining a maximum limit.
if the number you search for is in E1 (aka e1 = 2152) then use 1 of 3:
the easiest and probably the best:
1) =HLOOKUP(E1 & "-" & E1,A1:C1,1,true)
or
2) =index(a1:c1,1, max(ARRAYFORMULA( if($E$1>VALUE(left(A1:C1,4)),column(A1:C1),0) )) )
or
3) =index(A1:c1,1, min(ARRAYFORMULA( if(VALUE(right(A1:C1,4))>=$E$1,column(A1:C1),99) )) )
this the range you want
to get the column remove the index(a1:c1,1, .... ) leaving the .... in 2) and 3) or use the fo;;owin gin 1)
=HLOOKUP(E1 & "-" & E1,{A1:C1 ; arrayformula(column(A1:C1))},2,true)
glad to help

Resources