XLSXWriter: Formula with =CONCAT() Shows in Excel as "=#CONCAT()"? - excel-formula

When I do the following in XLSXWriter:
formula = "=CONCAT(A1, B1)"
worksheet.write_formula(1, 1, formula)
...I find the following in my workbook:
=#CONCAT(A1, B1)
...and the cell shows an #NAME error.
How can I correct this?

The issue is that the CONCAT() function is a so-called Future Function that was added in more recent versions of Excel (see the Formulas added in Excel 2010 and later section of the XlsxWriter docs).
You need to write the formula like this:
formula = "=_xlfn.CONCAT(A1, B1)"
However, as #teylyn points out there are many other simpler, and backward compatible ways of concatenating strings in Excel. You should use one of those instead.

Concat() is available on Windows or Mac with Office 2019 or Office 365 only.
Any other version of Excel will not recognize that function, hence the #Name! error.
Concat() replaces the Concatenate() function. Neither of these functions are required to concatenate text. The & operator often does the job much quicker, i.e. with less typing. For more sophistication, TextJoin() can be used (Office 365 / 2019 only).
The following formulas produce the same result.
=Concatenate(A1," - ",B1," - ",C1)
=Concat(A1," - ",B1," - ",C1)
=A1&" - "&B1&" - "&C1
=TEXTJOIN(" - ",TRUE,A1:C1)

Related

How to use MID, RIGHT and FIND functions in Excel?

I am trying to combine the State (NSW) and the Postal Code (2007) from cell F4 in the worksheet "Inventory", this is the text in cell F4: 310 Wattle StUltimo, 2007, NSW
What I trying to accomplish is this: NSW2007 using MID, RIGHT and FIND functions, but is giving me a headache
I tried this: =RIGHT(Inventory!F4,4) and I got so far this: NSW, what I need to get is NSW2007 so I am missing the MID (and FIND) part
thanks for your help in advance
With Office 365:
=LET(
rr,F4,
x,TRIM(TEXTSPLIT(rr,",")),
CONCAT(INDEX(x,COUNTA(x)-{0,1})))
For Older versions:
=TRIM(RIGHT(SUBSTITUTE(F4,",",REPT(" ",999)),999))&
TRIM(MID(SUBSTITUTE(F4,",",REPT(" ",999)),(LEN(F4)-LEN(SUBSTITUTE(F4,",",""))-1)*999,999))
If there is always only 2 , in the string and you want the 3rd and 2nd then we can simplify the above formula:
=LET(
rr,F4,
x,TRIM(TEXTSPLIT(rr,",")),
CONCAT(INDEX(x,{3,2})))
And
=TRIM(RIGHT(SUBSTITUTE(F4,",",REPT(" ",999)),999))&
TRIM(MID(SUBSTITUTE(F4,",",REPT(" ",999)),999,999))
I used the following Excel text formula.
Using the text in F4: "310 Wattle StUltimo, 2007, NSW"
To get NSW2007 from the text in F4 above use the following formula.
=CONCAT(TRIM(MID(F4,FIND(",",F4,FIND(",",F4,1)+1)+1,LEN(F4))),TRIM(MID(F4,FIND(",",F4,1)+1,FIND(",",F4,FIND(",",F4,1)+1)-FIND(",",F4,1)-1)))
To get NSW: =MID(F4,FIND(",",F4,FIND(",",F4,1)+1)+1,LEN(F4))
To get 2007: =MID(F4,FIND(",",F4,1)+1,FIND(",",F4,FIND(",",F4,1)+1)-FIND(",",F4,1)-1)
Then concatenate the two: concat (formula 1 above, formula 2 above).
This formula works regardless of the spaces (or no spaces at all) before and after the commas.
Hope this helps.

Excel sum formula over varying indices

I'm trying to reproduce the sum of the values in column I within one cell, without having to evaluate them for each row individually. For better understanding see the following screenshot:
I've sifted through endless INDEX/INDIRECT/etc. results both here and on Google, but can't seem to figure it out... Basically I want to just sum over the row-wise evaluations of this formula:
=-MAX($B$1-MAX(A$1:A1)+MIN(A$1:A1),0)
Note that the starting row of each evaluation is fixed.
Edit: the solution proposed by Scott works if Excel recognizes the LET() function, which does not seem to be the case for my work laptop even though it has Office 365 Pro Plus, probably this latest insider program is not enabled.
With the dynamic array formula in Office 365:
=LET(seq,SEQUENCE(COUNT(A:A)),rng,OFFSET(A1,0,0,seq),SUMPRODUCT(-(B1-MAXIFS(rng,rng,"<>")+MINIFS(rng,rng,"<>"))*(B1-MAXIFS(rng,rng,"<>")+MINIFS(rng,rng,"<>")>0)))

Trying to create a Excel Product formula Manual to Dynamic

I have been using Product formula manually since long to make calculations but now i want to make it work as Dynamic formula works.
But my result is not matching.
Below is the sheet link where both formulas are.
https://docs.google.com/spreadsheets/d/1w5PBoIycEFbjEW0tdOTZ1NDmvtqeHLw4/edit#gid=278652113
Using the following in G3 reproduces the data & result of F3:
=product(iferror(index(C:C,match(E2, A:A,0)),$A$1),filter(B:C,(A:A<E3)*(A:A>E2)),index(B:B,match(E3,A:A,0)))-1
For the first value I added a little workaround because your list is lacking January 1st of 2020. (That's the IFERROR directing to $A$1. I'm sure there's a cleaner solution for that, but.. it works.
The FILTER function is for Office 365.
For older excel versions use the following:
=product(OFFSET($B$1,MATCH(E2,A:A,0)-1,1),OFFSET($B$1,MATCH(E2,A:A,0),,COUNTIFS(A:A,"<"&E3,A:A,">"&E2),2),OFFSET($B$1,MATCH(E3,A:A,0),,,))-1
To workaround the value not being found for January 1st, 2020 I added this manually in A1

MS Excel 2010 MAXIFS equivalent in VBA Userform

I've created an Excel Userform to facilitate the data entry of new lines into a contract register. I have a field that auto-generates a new unique contract number by looking for the largest number in the list of contract numbers (Column A) and then adds 1. This formula works perfectly:
Me.tbContractNumber = Application.WorksheetFunction.Max(Sheet1.UsedRange.Columns(1)) + 1
I now have to add an IF criteria to filter out any contract numbers LESS Than "2018000". I have worked out how to do this in a normal Excel workbook using MAXIFS but apparently MAXIFS is not an available function in VBA?
Can someone suggest an equivalent VBA code to the below Excel formula? Thanking you in advance!
=MAXIFS(A2:A500,A2:A500,"<2018000")+1
EDIT Our work computers run 2010 and won't allow me to add the MS Office 16.0 Object Library so MAXIFS function will not work. I can get the following array formula to work but I have never used an array formula in VBA. Could someone please suggest an equivalent VBA code to the below Excel formula? Thanking you in advance!
{=MAX(IF(A:A<2018000,A:A)) +1}
If you're looking for the largest number anyway, do you need to filter out anything lower than 2018000? If you have at least one entry equal to/higher than 2018000, your end result will be higher regardless of the other entries.
I'm sure there are more efficient ways of doing it, but if you are happy with:
Me.tbContractNumber = Application.WorksheetFunction.Max(Sheet1.UsedRange.Columns(1)) + 1
then try:
me.tbContractNumber = Application.WorksheetFunction.MaxIfs(Sheet1.UsedRange.Columns(1), Sheet1.UsedRange.Columns(1), ">" & 2018000) + 1
...but apparently MAXIFS is not an available function in VBA. In VBA it is not present, but if you add the Excel 16.0 Object Library (second on the screenshot) to your project, you would be able to access it as follows:
Application.WorksheetFunction.MaxIfs 'Only in Excel
Excel.WorksheetFunction.MaxIfs 'Any host of VBA - Excel, Access, Word
The library is added by default, if you work in Excel. Concerning "translation" the working formula from Excel to VBA, check this:
https://stackoverflow.com/a/49363501/5448626
I just learned the Evaluate function! So equivalent of the array formula I want to use converts in VBA to:
Me.tbContractNumber = Evaluate("=MAX(IF(" & "A:A" & "<2018000," & "A:A" & "))+1")

Using vba functions in cell formula

I need to round two values and sum them then. The problem is, I have Czech version of MS Excel, and rounding function is called "Zaokrouhlit"
So my formula looks like =ZAOKROUHLIT(A1, 2) + ZAOKROUHLIT(A2, 2)
Now I'm thinking, what if I send my file to someone that is using excel in different language version, will it work?
So I tried default function =ROUND(A1, 2) + ROUND(A2, 2)
But my version of excel doesn't know anything about such a function.
Fortunatelly, I can use this function inside VBA subroutines, so my question is:
How to use VBA function inside formula?
try these localization solutions:
VanTed Bits: Excel VBA Tip: translate formulas between local language and English
excel-macro-inserting-internationally-valid-formula-during-run-time
there are several answers, and between them they should help you

Resources