I want to use textjoin. My formula right now works until it finds a blank cell, the Header is still joined.
What I like to have is that when a cell is empty, the header is ignored.
My formula until now is this, yet I don't know how to proceed further.
=TEKST.JOIN(" + ",TRUE,$A$2:$O$2&", "&A3:O3)
The desired outcome row 2 to 4:
Material+VZ
Driver+SW-12
And for row 5:
Material+VZ
Model+X4
Drive+SW-12
Hoping someone can help me on the way.
I have tried searching stackoverflow, and approaching the formula on a different way
I guess this is what you want, put in cell E2 the following formula:
=TEXTSPLIT(TEXTJOIN("",,MAP(A2:A5, B2:B5, C2:C5, LAMBDA(a,b,c,
IF(a<>"", A1&"+"&a&",", "") & IF(b<>"", B1&"+"&b&",", "")
& IF(c<>"", C1&"+"&c&",", "")))),,",",1)
You can encapsulate the IF logic in a user LAMBDA function (ADD) as follow:
=LET(ADD, LAMBDA(title, x, IF(x<>"", title &"+"& x &",", "")),
TEXTSPLIT(TEXTJOIN("",,MAP(A2:A5, B2:B5, C2:C5, LAMBDA(a,b,c, ADD(A1,a) &
ADD(B1,b) & ADD(C1,c)))),,",",1))
Here is the output:
Related
How can I substitute a cell reference for the formula it contains, in other words, "expand" or "derivate" cell references?
An example, and I know I could calculate it using PV(): Suppose I want to calculate the present value of a given amount, reductor, number of periods and discount rate and in a spreadsheet I have:
A2: 1 (number of periods)
B2: 5000 (amount)
C2: 0,8 (reductor)
G1: 6% (discount rate)
If I want to calculate the final result on D2, I would have to enter:
=(B2*C2)*(1+$G$1)^(-A2)
(I intentionally used some unnecessary parentheses above)
But if I wanted, for debugging, or for building a more complex formula with more nested calculations write on cells:
D2: =E2*F2^G2
E2: =B2*C2
F2: =1+$G$1
G2: =-A2
So that I could check every part of the calculation is working ok and that the final formula is well "assembled" (or to easily correct what might be wrong or change it to calculate something else, like future value, for which I would remove the minus sign on G2).
And after doing those steps use some function/shortcut/feature on cell D2 that would replace
"=E2*F2^G2"
for
"=(B2*C2)*(1+$G$1)^(-A2)"
(i.e. do E2 → (B2*C2) F2 → (1+$G$1) and G2 → (-A2)) so that the desired formula is built on the right place and I can get rid of the temporary cells.
The closest to this behaviour I could find was formulatext() function, but it works just for a single reference and always include the "=" if I do, for instance
=CONCAT(FORMULATEXT(E2);"*";FORMULATEXT(F2);"^";FORMULATEXT(G2))
results in
=B2*C2*=1+$G$1^=-A2
which is not the desired result.
What I was expecting to find was something like when one select a part of a formula and presses F9 and it substitutes it for the value, but applied for functions or intermediate steps.
As it really does not seem to exist a built-in funcion on Excel, I came out with a script for doing this based on the answer on Parsing and extracting cell references from Excel formulas?
Works on Excel 365 (may work on other versions as well), replaces references on active cell only, does not work on cells that contain intervals (for instance, it will fail on a cell that contains =sum(A1:A5) ) and the contents of the precedent cells will end up enclosed in parentheses. It also does not replace "locked" cells (=$B$2 won't be replaced as well).
In summa, it is not perfect, maybe it's not ellegant too, but it seems to be as good as I needed and works on the proposed scope.
Sub ReplacePrecedents()
Dim r As Range, rr As Range
With ActiveCell.Range("A1")
' store the contents of the cell
parsedcontents = .Formula
Set r = .DirectPrecedents
' iterate throughout all precedents
For Each rr In r
' store each one between parentheses
appendstr = "("
' check whether first character is a "=" or a value
If StrComp(Left(rr.Range("A1").Formula, 1), "=") = 0 Then
appendstr = appendstr & Right(rr.Range("A1").Formula, Len(rr.Range("A1").Formula) - 1)
Else
appendstr = appendstr & rr.Range("A1").Formula
End If
appendstr = appendstr & ")"
' do the magic
parsedcontents = Replace(parsedcontents, rr.Address(0, 0), appendstr)
Next rr
' write the parsed string to the cell
.Formula = parsedcontents
End With
End Sub
Thank you for everyone that replied, I guess I still do not have privileges enough to upvote a comment, as soon as I do, I will.
I'm trying to use Application.Evaluate method for evaluating a Sumif formula in which the criteria is ">="
Following is the line of code I'm trying to get an evaluation of
So I have Order Numbers 1 to 15 in Cell E1 to E15, and their Respective Amounts in Cell F1 to F15.
In J1 the user inputs his Order Number. Amount over and above that order number will be totaled and displayed using Sumif Function.
Now I want to find this answer using Application.Evaluate
MsgBox( Application.Evaluate("=SUMIF(E1:E15, ">=" & J1, F1:F15)"))
I get greeted with True or False Message Box.
Now I am guessing the inverted commas in Sumif Function ie. ">=" is causing this problem. Hence to fix this, I amended the function to
MsgBox( Application.Evaluate("=SUMIF(E1:E15, """">="""" & J1, F1:F15)"))
However now it returns 0, although there are values in it.
I would really appreciate if someone could help me understand a way around it
*Note: Please do not suggest to use any other function. I want to know it purely from Application.Evaluate perspective, as my further line of code depends on it. *
Thanks.
All quotes inside the string must be doubled:
">="
Should be
"">=""
Also:
Application.Evaluate
will work on the active sheet, thus if the wrong sheet is active the sumifs will be done on the wrong sheet since no sheet names are provided in the formula itself.
Use
Worksheets("Sheet1").Evaluate
Changing "Sheet1" to your sheet.
So in total:
MsgBox Worksheets("Sheet1").Evaluate("=SUMIF(E1:E15, "">="" & J1, F1:F15)")
I have a table in my workbook that pulls information from another sheet. In column A there are names; A1=Tom, A2=Sarah, A3=Steve, etc.. Column B has dates; B1=July26, B2=August08, B3=July26, etc.
There are 10 rows in my table. What I'm trying to do is compress the information down into a single cell C1, and have it as a single line of text. So for this example: "Tom,Steve: July26, Sarah: August08"
Right now I've been building an IF statement to compare, but I was wondering if there was a better way; one that doesn't risk a typo mid way that misses something.
This is what I have (I've started from the bottom (row 10) and building up: =IF(B9<>B10,A9&": "&B9&" "&A10&": "&B10,A9&","&A10&": "&B9)
Any help would be appreciated, thanks
I think that your process of building from the bottom up is the correct way. Otherwise a single formula would be too complicated, and VBA might be necessary.
To build from the bottom up, this is the formula you need at C10. Enter it then copy/paste into C1:C10.
C10:
=A10 & IF(B10=B11, ",", ": " &TEXT(B10, "mmmmdd") & ". ") & C11
p.s. it supposes that your column B contains dates formatted this way. If they are actually text, then replace TEXT(B10, "mmmmdd") with simply B10:
=A10 & IF(B10=B11,",", ": " & B10 & ". ") & C11
Ok. I'm Having A Problem With A formula That Seems Really Basic. It Uses The If Function. Here's What I Need.
If(b2:b50<>"",IF(b2:b50"607734",e2:e50="Patriot"))
So Basically If Between b2-b50 Has The Number "607734" I Want e2-e50 To Display "Patriot"
You need to put the IF statement in the cell where you want the value. For example, in E2, enter =IF(B2="607734", "Patriot", "") and drag it down to E50.
For each cell you have to enter the formula, which goes like this.
If(logical_test,value if true, value if false)
So, if b2 =607734 then c2 = "Patriot" else c2= " "
Now as formula we can write this as
if(b2=607734,"Patriot","")
similarly, for other cells(c3,c4,c5,c6....c50) we have formula in each cell as :
if(b3=607734,"Patriot","")
if(b4=607734,"Patriot","")
if(b5=607734,"Patriot","")
if(b6=607734,"Patriot","")
........
........
if(b50=607734,"Patriot","")
Your IF statements don't satisfy the else conclusion.
The format of an IF statement in Excel is as follows:
IF(parameter, what to do if parameter is true, what to do if parameter is false).
Right now you've filled in the first two variables for the IF command, but you left the third blank.
e.g.
Could have:
If(b2:b50<>"",IF(b2:b50"607734",e2:e50="Patriot", " ")," ")
And in that case it would put a space in the cell if the first two conditions are not met.
I am trying to adapt the following formula (counting instances of values between 0 and 24):
=COUNTIFS(cancellations!AG2:AG408,">0",cancellations!AG2:AG408,"<24")
(formula evaluates to 75), to something like:
=COUNTIFS(cancellations!AG2:AG408,">0",cancellations!AG2:AG408,INDIRECT("" & "<" & B1*24 & ""))
but this evaluates to zero. (B1 = 1 in the above example.)
When I view the INDIRECT function inside the fx box it evaluates correctly. Not sure of what I am doing wrong.
When applied in a cell like so:
=INDIRECT("" & "<" & B1*24 & "")
It shows #REF!.
The INDIRECT function returns a reference to a range. You can use this function to create a reference that won't change if row or columns are inserted in the worksheet. Or, use it to create a reference from letters and numbers in other cells.
=COUNTIFS(cancellations!AG2:AG408,">0",cancellations!AG2:AG408,B1)
should work where B1 contains <24.
So, I read up the COUNTIFS() function in more detail and I found that the following works
=COUNTIFS(cancellations!AG2:AG408,">0",cancellations!AG2:AG408,"<"&B1*24)
Where:
B1=1