I have a typical book index in a spreadsheet that goes like this:
I need Excel to recognize the different integers in the same cell and add a constant each one of them.
Let's say the constant is 5
The result should be like this:
I couldn't get excel to recognize the different values in a cell.
My two cents, assuming Excel ms365:
Formula in B1:
=BYROW(A1:A3,LAMBDA(a,LET(X,TEXTSPLIT(a,", "),TEXTJOIN(", ",,IFERROR(X+C1,X)))))
Or, if no access to TEXTSPLIT(), then use:
=BYROW(A1:A3,LAMBDA(a,LET(X,FILTERXML("<t><s>"&SUBSTITUTE(a,",","</s><s>")&"</s></t>","//s"),TEXTJOIN(", ",,IFERROR(X+C1,X)))))
Or, if no access to BYROW(), you'd have to drag the following:
=LET(X,FILTERXML("<t><s>"&SUBSTITUTE(A1,",","</s><s>")&"</s></t>","//s"),TEXTJOIN(", ",,IFERROR(X+C$1,X)))
Not sure if this could be done smoothly and without using long and complex formulas.
Why don't you try to split the cell into multiple columns (Data > Data Tools > Text To Columns > Delimited and select Comma as delimiter). Once you have all different values is separate columns, it would be easy to apply formulas and add the constant.
After that, you could use CONCATENATE formula to merge texts and numbers back to single value in a single column.
Hope this helps.
I would separate the text and each value into separate cells, then use & to combine into the format you want, something like so:
=A1&", "&B1+G1&", "&C1+G1&", "&D1+G1
where A1 contains "Trauma" and B1 contains 15, C1 contains 17 and D1 contains 25. G1 holds the constant 5.
See
This is what I have tried,
Formula Applicable To Only O365 Beta Channel (Insiders).
• Formula used in cell B1
=TEXTJOIN(", ",,TEXTBEFORE(A1,", ",1),TEXTSPLIT(TEXTAFTER(A1,", ",1),", ")+5)
Or, if you are not using the above Excel Version, but using either Excel 2019, 2021 or Regular O365, then,
• Formula used in cell B1
=TEXTJOIN(", ",,LEFT(A1,FIND(",",A1)-1),IFERROR(
FILTERXML("<a><b>"&SUBSTITUTE(A1,", ","</b><b>")&"</b></a>","//b")+5,""))
Edit
One improvised approach:
=TEXTJOIN(", ",,TEXTBEFORE(A1,", ",1),IFERROR(TEXTSPLIT(A1,", ")+5,""))
You can also accomplish this task quite easily with Power Query.
Related
I am trying to clean some data with this format:
A1 B1 C1
"0,1,0,E,1" "0,0,0,E" "0,1,1,1,2,E"
To obtain the information, I will need to sum up each cell individually, and then calculate the sum over a row.
So far, I have replaced all of the "E"s (for empty) with no data, which removed the E's, and I have replaced all of the commas with "+" signs to add the numbers in the cell. To run the formula of each cell, I will need to now place an "=" in front of each text string, however, if I copy it in with something like "="="&A1" the formula will not run because excel is reading the = as a letter or symbol and not an operator. Do you know of a way to fix this problem?
Thank you so much!
I think this will work for your version ...
=SUM(FILTERXML("<d><c>" & SUBSTITUTE(A1,",","</c><c>") & "</c></d>","//c"))
That's applied like below ...
... there's always someone smarter than me but that seems to work.
It’s not an in place replacement but it keeps your source data intact and provides a nice reconciliation point.
Using a separate sheet for each column of values, given data in cell A1 of
0,0,0,1,0,1,1,E,1,0
In C1, enter the formula
=IFERROR(MID(SUBSTITUTE(SUBSTITUTE($E$14,",",""),"E",""),COLUMN()-2,1)*1, "")
and drag the fill handle to to the right for as many cells as the longest number of data points you have.
Enter your SUM()formula in B1 (you can use the shortcut ALT + =).
Have you tried something like this, please refer the image, where its showing as per your required output, three alternative formulas
1.) Formula used in cell B2
=SUMPRODUCT(IFERROR(--MID($A2,ROW(INDIRECT("1:"&LEN($A2))),1),0))
2.) Formula used in cell D2
=SUMPRODUCT(IFERROR(--MID($C2,SEQUENCE(LEN($C2)),1),0))
The 2nd formula is applicable to Excel 2021 & O365 Users only
3.) Formula used in cell F2
=SUM(IFERROR(--MID($E2,ROW($1:$1000),1),0))
This is an array formula, so requires to press CTRL SHIFT ENTER !
Here is an update, the last formulas, which i have shared, shall work only when the digits are less than 10, however the present formula, shall work for all number of digits,
Formula used in cell B17
=SUMPRODUCT(IFERROR(--MID(SUBSTITUTE($A17,",",REPT(" ",100)),COLUMN(A1:Z1)*99-98,100),0))
Please adjust your range accordingly as per your data.
I have several cells that calculate totals from a single cell from multiple worksheets, in this case "Y3" from each of the sheets that are in Week, where n is an integer from 1 through 10:
=SUMPRODUCT(COUNTIF(INDIRECT("'Week"&{1,2,3,4,5,6,7,8,9,10}&"'!Y3"),"W"))
I would like to have a cell in my workbook that contains, A1:
1,2,3,4,5,6,7,9,10
So that way I can update only one cell when I add a worksheet to be counted. I've tried a few things and nothing seems to work.
Your formula : =SUMPRODUCT(COUNTIF(INDIRECT("'Week"&{1,2,3,4,5,6,7,8,9,10}&"'!Y3"),"W"))
This formula only work if you have 10 sheets with named Week1,Week2,Week3….Week10
But if you have less than 10 sheets e.g. Week1,Week2,Week3….Week9, your formula will fail and return "#REF!" error
The formula workaround is wrapping with a IFERROR() and become :
=SUMPRODUCT(IFERROR(COUNTIF(INDIRECT("'Week"&{1,2,3,4,5,6,7,8,9,10}&"'!Y3"),"W"),0))
However, if you wanted the formula acting dynamic and in A1 enter : 1,2,3,4,5,6,7,9,10
But 1,2,3,4,5,6,7,9,10 is a text string, you need converted it to an array. Using FILTERXML() can do the work of which available since Excel 2013
This is an array formula you need to confirm by pressing CTRL+SHIFT+ENTER instead of just ENTER:
=SUM(IFERROR(COUNTIF(INDIRECT("'Week"&FILTERXML("<a><b>"&SUBSTITUTE(A1,",","</b><b>")&"</b></a>","//b")&"'!Y3"),"W"),0))
EDIT 1 :
And,
if you haven't Excel 2013, you could use this longer array (CSE) formula instead
=SUM(IFERROR(COUNTIF(INDIRECT("'Week"&TRIM(MID(SUBSTITUTE(","&A1,",",REPT(" ",99)),ROW(INDIRECT("1:"&LEN(A1)-LEN(SUBSTITUTE(A1,",",))+1))*99,99))&"'!Y3"),"W"),0))
After that,
you can make adjustment to A1 number without changing formula contents
AFAIK you can't do that with a formula if you place the sheet list in a single cell I stand corrected: see bosco_yip's answer! (although you could with a UDF).
But, if you place your sheet list in a column, you can do this (using OFFSET, the list is dynamic, but must be the only data in that column. There are alternatives if that doesn't suit you):
=SUMPRODUCT(COUNTIF(INDIRECT("'Week"&TRANSPOSE(OFFSET(A1,1,0,COUNTA(A:A)-1,1))&"'!Y3"),"W"))
Applying the FILTERXML method, to create a non-array formula
=SUMPRODUCT(COUNTIF(INDIRECT("'Week"&FILTERXML("<a><b>"&SUBSTITUTE(A2,",","</b><b>")&"</b></a>","//b")&"'!Y3"),"W"))
I am trying to come up with a excel formula to Look Up every word separated by either a space or comma in a cell, match each of the words against a list of words and return the found word in another column.
As an example:
So the ColorFamily column should be a formula
I have tried using VLOOKUP e.g.
=VLOOKUP(H3,color_family!$A$3:$A$19,1,FALSE)
But the limitation is that it does not iterate through every single word in the cell. Is it possible to do this using Excel Formula or is VBA required?
Enter as an array formula (ctrl+shift+enter):
=TEXTJOIN(" ",TRUE,IF(ISERR(FIND(color_family!$A$3:$A$19,H3)),"",color_family!$A$3:$A$19))
I couldn't make much sense of the accepted answer but here is a similar approach. This works in Excel 365, and depends on its dynamic array functionality to work.
Here is the spreadsheet layout I am working with:
I have used spaces to separate the values in the colour list but the solution could be generalised to handle commas etc.
The steps I've used to build the formula needed are:
Group valid list into a single string using TEXTJOIN: TEXTJOIN(",",TRUE,$A$7:$A$9)
Split the Colour cells into columns of words (uses dynamic array functionality). There is a write up on how to do this here: https://www.mrexcel.com/board/excel-articles/split-text-cell-into-columns-of-words.19/ e.g. for A2 this formula produces Black and Red in separate columns
TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",LEN(A2))),SEQUENCE(1,LEN(A2)-LEN(SUBSTITUTE(A2," ",""))+1,1,LEN(A2)),LEN(A2)))
Use FIND to look for the text in each column above, in the valid list
If FIND returns a number (checking with ISNUMBER) return the text, otherwise ""
This is all still in separate columns so now use TEXTJOIN to combine the results together in a comma separated list.
Final formula in B2:
`=TEXTJOIN(",",TRUE,IF(ISNUMBER(FIND(TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",LEN(A2))),SEQUENCE(1,LEN(A2)-LEN(SUBSTITUTE(A2," ",""))+1,1,LEN(A2)),LEN(A2))),TEXTJOIN(",",TRUE,$A$7:$A$9))),TRIM(MID(SUBSTITUTE(A2," ",REPT(" ",LEN(A2))),SEQUENCE(1,LEN(A2)-LEN(SUBSTITUTE(A2," ",""))+1,1,LEN(A2)),LEN(A2))),""))`
which can be copied into B3, B4 etc giving final result:
I have data that extends from column A1 to F1. All the cells contain VLOOKUP formulas looking up data from an external Excel file.
I want to be able to insert a formula in column G1 to count the number of times a certain filename is used in columns A1 to F1.
I know that if the data in cells A1 to F1 were NOT formulas I could use something like the below in G1 if I was searching for the string "filename.xlsx" using wildcards:
=COUNTIF(A1:F1, "*filename.xlsx*")
However, as A1 to F1 contain formulas, I assume I would need to use FORMULATEXT, in order to look within the VLOOKUPs. I have tried the below, but it doesn't work:
=COUNTIF(FORMULATEXT(A1:F1),"*filename.xlsx*")
Does anyone know if there is a way to do this? it would also be good if the criteria within the COUNTIF was a cell reference. However, that isn't essential.
Thanks
Try using this array formula
=COUNT(SEARCH("filename.xlsx",FORMULATEXT(A1:F1)))
confirm with CTRL+SHIFT+ENTER
or a non array version.....
=SUMPRODUCT(ISNUMBER(SEARCH("filename.xlsx",FORMULATEXT(A1:F1)))+0)
I have an Excel document that has a date column (A) and a column containing strings (B) one one sheet. On another sheet, I am doing calculations. If the cell in column A is between DATE(2012,1,1) and DATE(2012,6,1) AND the same row in column B contains "string" in any part (string) then it should count that row. Google mentioned using SUMPRODUCT but I was only able to get date between to work. Below is the SUMPRODUCT for date between.
=SUMPRODUCT(--('Sheet1'!A:A>=DATE(2012,1,1)),--('Sheet1'!A:A>=DATE(2012,6,1)))
I tried using this for the final value but it is incorrect.
=SUMPRODUCT(--('Sheet1'!A:A>=DATE(2012,1,1)),--('Sheet1'!A:A>=DATE(2012,6,1)),--('Sheet1'!B:B="*"&"string"&"*"))
EDIT: Apparently the above works, but the string must be EQUAL to the value. * is not being recognized as a wildcard.
Thanks.
If you are using whole columns in SUMPRODUCT you must have Excel 2007 or later (otherwise that doesn't work), and you can use wildcards in COUNTIFS
=COUNTIFS('Sheet1'!A:A,">="&DATE(2012,1,1),'Sheet1'!A:A,"<="&DATE(2012,6,1),'Sheet1'!B:B,"*String*")
The issue you're running into is due to the fact that you can't use wildcards in that way in a SUMPRODUCT. A way that you can get around it (assuming you need to use SUMPRODUCT) is to use either SEARCH or FIND to create the necessary array for use in the SUMPRODUCT. Here is an example that has your target string in cell D1 (note that this needs to be entered as an array formula with Ctrl+Shift+Enter):
=SUMPRODUCT(
--(Sheet1!A:A>=DATE(2012,1,1)),
--(Sheet1!A:A<=DATE(2012,6,1)),
IFERROR(IF(SEARCH(D1,Sheet1!B:B)>0,1,0),0))
IFERROR accounts for the non-matches but is an Excel 2007 feature. If you're not using Excel 2007, you can try:
=SUMPRODUCT(
--(Sheet1!A:A>=DATE(2012,1,1)),
--(Sheet1!A:A<=DATE(2012,6,1)),
IF(ISERROR(IF(SEARCH(D1,Sheet1!B:B)>0,1,0)),0,IF(SEARCH(D1,Sheet1!B:B)>0,1,0)))
Also, in your example formula, you'll need switch the sign to <= in the comparison to June :)
Sumproduct does not allow for wildcards. You can search for strings using ISNUMBER(SEARCH("string",range)). The formula is below.
=SUMPRODUCT(--('Sheet1'!A:A>=DATE(2012,1,1)),--('Sheet1'!A:A<=DATE(2012,6,1)),--(ISNUMBER(SEARCH("string",'Sheet1'!B:B))))
What version of Excel are you using? If it is 2007 or later, you can use COUNTIFS; here is a link to the syntax. You may have to use two columns, even using COUNTIFS. On Sheet2, column A should check whether Sheet1, column B contains "string" using the following formula:
=IF(ISERR(FIND("string",'Sheet1'!B1)), FALSE, TRUE)
You will need to replace 'Sheet1'!B1 with whatever cell you need, then drag it down to make it have the same number of rows as your Sheet1, column B. Then you can use COUNTIFS:
=COUNTIFS('Sheet1'!A:A, ">=" DATE(2012,1,1), 'Sheet1'!A:A, ">=" & DATE(2012,6,1), A:A, TRUE.