How to give reference to a row number in excel formula? - excel

I need this formula: C(n) = B(n)*A5. (n is the row number)
Literally, multiply the current selected row number in column B with A5
I tried =ROW function for creating a reference but failed.
I tried with this formula: C(2) =MULTIPLY(B=ROW(),A5) thinking it will be parsed to C(2) =MULTIPLY(B2,A5)

You have two options to accomplish this:
1. INDEX() formula:
=INDEX(B:B,ROW())*A5
2. INDIRECT() formula:
=INDIRECT("B"&ROW())*A5
Where ROW() is the number of cell you're entering this formula into.

Found it.
=MULTIPLY(INDIRECT("F" & ROW()),INDIRECT(("G" & 2)))
INDIRECT(("G" & 2)) even makes it better if you want to drag and copy the functionality to all the rows below.

Related

How to do an if statement

This question is linked to Formula to remove every middle name in a cell in Excel.
I basically want to make an if else statement in excel. So the IFchecks if the cell is equal to "Gian" OR"Pier", if the condition is confirmed the formula proceeds to use this other formula
=IFERROR(LEFT(A2,FIND(" ",A2)-1),A2)
Sorry guys idk how to do it in an excel way. I can show you in for example in a Java or C way.
if(A2=="Pier" || A2=="Gian")
=IFERROR(LEFT(A2,FIND(" ",A2)-1),A2) \\the excel formula that deletes every second/third name if the cell
if formula in excel that checks a condition and if its verified it proceeds to use another excel formula
You could try the following as per your Excel Versions
• Formula used in cell B2
=IF(OR(TEXTBEFORE(A2&" "," ")={"Pier","Gian"}),A2,TEXTBEFORE(A2&" "," "))
Or, in cell C2
=IF(OR(LEFT(A2&" ",FIND(" ",A2&" ")-1)={"Pier","Gian"}),A2,LEFT(A2&" ",FIND(" ",A2&" ")-1))
Just adding the use of LET() which makes it simpler,
• Formula used in cell B2
=LET(x,TEXTBEFORE(A2&" "," "),IF(OR(x={"Pier","Gian"}),A2,x))
Or, Formula used in cell C2
=LET(x,LEFT(A2&" ",FIND(" ",A2&" ")-1),IF(OR(x={"Pier","Gian"}),A2,x))
Using MAP() to Spill as one dynamic array formula but the logic remains same.
• Formula used in cell D2
=MAP(A2:A6,LAMBDA(m,
LET(x,TEXTBEFORE(m&" "," "),
IF(OR(x={"Pier","Gian"}),m,x))))
you have to use the AND(...) and OR(..) for chaining logical conditions.
Here's an example

How do I give cell values as parameters to ROW() formula in MS Excel?

Giving static numerical values to the ROW() formula like ROW($1:$2)) works perfectly (obviously), but I have both the values it requires in cells... Here what I am trying to build : ROW($C3:$E4)). This works, but gives me the value 3 (C3 cells's row).
What should I do in order to get the value inside C3 cell to pass it to ROW()?
For Excel 365:
If we enter:
=ROW(7:13)
in D1, we get:
Now if G1 contains 7 and G2 contains 13, then:
=ROW(INDIRECT(G1 & ":" & G2))
will give us the same result:
Don't use a volatile INDIRECT set-up when there exists a non-volatile alternative:
=ROW(INDEX(A:A,G1):INDEX(A:A,G2))
which is volatile only at workbook open.

Is there any way to specify an offset for a cell in a named range within a formula?

Suppose I've created these named ranges: Apples = "A1:A3", Pears = "B1:B3"
Then putting the formula "=Apples + Pears" in cell C3 is the same as "=A3 + B3"
Is there some way to specify an offset in the "=Apples + Pears" formula so that cell C3 refers to "=A3 + B2" instead?
In other words, how would an offset for "Pears" be specified so that it refers to B2 instead of B3?
Thanks in advance for any help!
Edit: I would like the formula to be relative, so that if I copied it to cell C2 it would refer to "=A3 + B1"
You can use the ROW() function of the current cell to get an index that is automatically updated when you copy the formula. This formula goes into C3, then when you drag it up, it automatically adjusts the index for Pears.
=INDEX(Apples,3,1)+INDEX(Pears,ROW(C3)-1,1)
Note that if your real data doesn't start in row 2, you'll need to subtract the additional amount from the row function to allow for the additional rows.
Use the INDEX function to specify a cell within a range, named or conventional.
=index(apples, 3, 1) + index(pears, 2, 1)
The OFFSET function will do the trick to move from cell B3 one cell up:
For numbers use the following function (e.g. number 3):
=A3+OFFSET(INDIRECT(ADDRESS(MATCH(3,B:B,0),2)),-1,0)
And for strings use this function:
=A3&OFFSET(INDIRECT(ADDRESS(MATCH("Pears",B:B,0),2)),-1,0)

What function can i use for my excel example?

I have the next situation:
Column A - represent my values.
Column B,C,D - are values resulted from an vlookup formula.
What I need is:
I need to check if a value from A1 is found in B1 or C1 or D1 and if value is TRUE, i want to return A1 value in E1.
I tried with many functions but nothing helped me. My last try is with multiple vlookup functions but it doesn't work...
=VLOOKUP($A2,CHOOSE({1,2,3},$C$2:$C94319&$D$2:$D$94319&$E$2:$E$94319,$A$2:$A$94319),1,0)
Please Help me!
Thanks!
Here is the formula that you can use (assuming your data starts from row 1):
=IF(IFERROR(MATCH("*" & A1 & "*",B1:D1,0),FALSE), A1,"Not Found")

Count until first three consecutive blank columns

I am having trouble mixing the counting cells with value '1' until the first three consecutive blank cells. The following image as the example:
Is it possible to do it only with Excel formulas or do I have to use other code?
Your problem is not so much identifying the three terminating blank cells as trailing the last three blank cells off to 2 cells then 1 cell at the end of the B:Z range. If you can extend the range to guaranteed blank cells in AA:AC then you can use an array formula¹ to accomplish the 'three-blank-cell-match' with a progressively staggered range.
    
The array formula¹ in A2 is,
=COUNTIF(B2:INDEX(B2:AA2, MATCH(1E+99, IF(B2:AA2="", IF(C2:AB2="", IF(D2:AC2="", 1E+99))), 0)), 1)
Fill down as necessary.
counting cells with value '1' until the first three consecutive ...
The formula may be more universal if counting ones is the primary task. Simply switch the conditions to any three consecutive cells that are not i.
    
The array formula¹ in A2 is,
=COUNTIF(B2:INDEX(B2:AA2, MATCH(1E+99, IF(B2:AA2<>1, IF(C2:AB2<>1, IF(D2:AC2<>1, 1E+99))), 0)), 1)
Fill down as necessary. Note that I've modified the last row to show more matches.
¹ Array formulas need to be finalized with Ctrl+Shift+Enter↵. Once entered into the first cell correctly, they can be filled or copied down or right just like any other formula.
I think most worksheet functions are going to get pretty messy for this type of task, however, one way you could go about it is something like this...
=COUNT(INDIRECT("R[0]C[1]:R[0]C[" & FIND("0",CONCATENATE(SUM(B1:D1),SUM(C1:E1), SUM(D1:F1), SUM(E1:G1), SUM(F1:H1), SUM(G1:I1), SUM(H1:J1), SUM(I1:K1), SUM(J1:L1), SUM(K1:M1), SUM(L1:N1), SUM(M1:O1), SUM(N1:P1), SUM(O1:Q1), SUM(P1:R1), SUM(Q1:S1), SUM(R1:T1), SUM(S1:U1), SUM(T1:V1), SUM(U1:W1), SUM(V1:X1), SUM(W1:Y1), SUM(X1:Z1), SUM(Y1:AA1), SUM(Z1:AB1))) & "]",FALSE))
This works for columns A to Z, of course, it ends up being very long. Alternatively, more options are on the table if you enable iterative calculations, then you can use something like this.
In A1: =COUNT(INDIRECT("R[0]C[3]:R[0]C[" & B1 & "]", FALSE))
In B1: IF(C1 > 0,B1+ 1,B1)
In C1: =COUNT(INDIRECT("R[0]C[" & B1 - 2 & "]:R[0]C[" & B1 & "]",FALSE))
The problem with this is it requires iterative calculations and is only valid if it begins its iteration with range B1 having a starting value of 0. One way you could streamline an iteration reset would be with a switch like this...
In B1: =IF(B2="",IF(C1 > 0,B1+ 1,B1),0)
A VBA function is likely your best bet if you can pull it off. You could build something like this...
Function CountBeforeBlanks(R As Range)
For i = 1 To R.Count
CountBeforeBlanks = CountBeforeBlanks + R(i)
If Application.WorksheetFunction.Count(R(i), R(i + 1), R(i + 2)) = 0 Then
Exit Function
End If
Next
End Function
Enter this formula in cell A2 and then copy downward as far as needed:
=COUNTA(OFFSET(B2,,,,-1+FIND("111",--(B2="")&--(C2="")&--(D2="")&--(E2="")&--(F2="")&--(G2="")&--(H2="")&--(I2="")&--(J2="")&--(K2="")&--(L2="")&--(M2="")&--(N2="")&--(O2="")&--(P2="")&--(Q2="")&--(R2="")&--(S2="")&--(T2="")&--(U2="")&--(V2="")&--(W2="")&--(X2="")&--(Y2="")&--(Z2=""))))
.
UPDATE
Here is a shorter version that works the same way. No extra columns required:
=COUNTA(OFFSET(B2,,,,-1+FIND("000",
RIGHT(DEC2BIN(SUM(256,(LEN(B2:I2)>0)*2^{7,6,5,4,3,2,1,0})),8)&
RIGHT(DEC2BIN(SUM(256,(LEN(J2:Q2)>0)*2^{7,6,5,4,3,2,1,0})),8)&
RIGHT(DEC2BIN(SUM(256,(LEN(R2:Y2)>0)*2^{7,6,5,4,3,2,1,0})),8)&--(Z2<>"")
)))
This is an array formula and must be confirmed with Ctrl+Shift+Enter.

Resources