I have a dataset which looks like the following:
A
B
C
D
E
1
4
5
2
3
6
1
3
I need to create a column which concatenates the cells in each row from the first cell with a value, to the last cell with a value, even if there are blanks in the middle. These need to be separated by a semi-colon. So the output for the first row would be 1; ;4;5. Second row would be 2;3; ;6. Third row would be 1; ; ; ;3.
As it stands I have managed to add a couple of formulas which identify the start and end column references within the range for each row (i.e. first row starts column 1, ends column 4).
The formula for finding first non-blank cell ref in row:
={MATCH(FALSE(ISBLANK(H6:AB6),0)}
The formula for finding last non-blank cell ref in row:
=AGGREGATE(14,6,(COLUMN(H6:AB6)-COLUMN(H6+1)/(H6:AB6<>""),1)
I am struggling with how to get the formula to use the starting column number for that row and pull back subsequent cell values with the ; separator until it gets to and includes the last column reference number.
A FILTERXML() alternative:
Formula in G1:
=TEXTJOIN(";",0,IFERROR(FILTERXML("<t><s>"&TEXTJOIN("</s><s>",0,A1:E1)&"</s></t>","//s[.!='' or (following::*!='' and preceding::*!='')]"),""))
Use in J1 or Any of your Required Cell
=IF(AND(A1="",B1="",C1="",D1="",E1=""),"",CONCATENATE(A1,IF(AND(B1="",C1="",D1="",E1=""),".",IF(A1="",""," ;")),B1,IF(AND(C1="",D1="",E1=""),IF(AND(B1="",C1="",D1="",E1=""),"","."),IF(AND(A1="",B1=""),""," ;")),C1,IF(AND(D1="",E1=""),IF(AND(C1="",D1="",E1=""),"","."),IF(AND(A1="",B1="",C1=""),""," ;")),D1,IF(E1="",IF(AND(D1="",E1=""),"","."),IF(AND(A1="",B1="",C1="",D1=""),""," ;")),E1,IF(E1="","",IF(E1="","","."))))
Hope Thats what you actually want.
Just to answer the part of your question that asks about how to use the column number of first and last non-blank cell to get the result without leading and trailing semicolons, your formula would look like this:
=TEXTJOIN(";",0,INDEX(1:1,MATCH(FALSE,ISBLANK(A1:E1),0)):INDEX(1:1,AGGREGATE(14,6,(COLUMN(A1:E1)-COLUMN(A1)+1)/(A1:E1<>""),1)))
or shorter:
=TEXTJOIN(";",0,INDEX(1:1,MATCH(FALSE,ISBLANK(A1:E1),0)):INDEX(1:1,LOOKUP(2,1/(A1:E1<>""),COLUMN(A1:E1))))
The only advantage of using aggregate is that you don't need to array-enter it in earlier versions of Excel, but you don't need to array-enter the lookup formula either so I would tend to use that (and anyway in this case you probably need to array-enter the whole formula pre Excel-365).
This isn't too bad, but unfortunately if you wanted to make blanks into zeroes you would have to repeat most of the formula, unless you have Excel 365 and can use Let:
=TEXTJOIN(";",0,IF(INDEX(1:1,MATCH(FALSE,ISBLANK(A1:E1),0)):INDEX(1:1,LOOKUP(2,1/(A1:E1<>""),COLUMN(A1:E1)))="",0,
INDEX(1:1,MATCH(FALSE,ISBLANK(A1:E1),0)):INDEX(1:1,LOOKUP(2,1/(A1:E1<>""),COLUMN(A1:E1))) ))
If you have Excel 365, you can search from the end of the array using Xmatch:
=TEXTJOIN(";",0,INDEX(1:1,XMATCH(TRUE,A1:E1<>"")):INDEX(1:1,XMATCH(TRUE,A1:E1<>"",0,-1)))
Look at the picture below: I have 3 cells containing the starting number(B4=1), the increment number (C4=2) and the desired amount of numbers in the list (D4=3). In F4 I would like to have a list of comma separated values in F4 (1,3,5).
I tried something with REPT : B4&REPT(","&1(something like+C4);D4-1), but I do not know how to increase each repetion value.
Consider:
=TEXTJOIN(",",TRUE,SEQUENCE(C1,,A1,B1))
with the starting value in A1, the increment in B1 and the number of items in C1.
IN B1 I have: 3,4,5
IN B2 I have the sum of these numbers 12
I would like to add these together and the sum to appear in B3
So, for B3, I need to tell excel to reference the cell holding the numbers, then add them together. This way, once I create the original formula, I can drag it through the remaining cells.
Reason is: The sum of these numbers (B2), are pulling the sum from a different location within the spreadsheet. I need to make sure these numbers match.
Thank you
Alternate solution (if exactly three numbers separated by a comma):
=SUMPRODUCT(--MID(SUBSTITUTE(B1,",",REPT(" ",99)),99*(ROW($1:$3)-1)+1,99))
Or, to make the formula more dynamic so that the B1 cell can have any quantity of numbers, as long as they are separated by a comma:
=SUMPRODUCT(--MID(SUBSTITUTE(B1,",",REPT(" ",99)),99*(ROW(INDIRECT("1:"&LEN(B1)-LEN(SUBSTITUTE(B1,",",""))+1))-1)+1,99))
Assuming you always have three numbers separated by a coma.
=LEFT(B1,FIND(",",B1)-1) + MID(B1,FIND(",",B1)+1,FIND(",",B1,FIND(",",B1)+1)-FIND(",",B1)-1) + MID(B1,FIND(",",B1,FIND(",",B1,FIND(",",B1)+1))+1,100)
If I break down the formula it's a bit simpler to see what is going on.
1st number:
LEFT(B1,FIND(",",B1)-1)
2nd number:
MID(B1,FIND(",",B1)+1,FIND(",",B1,FIND(",",B1)+1)-FIND(",",B1)-1)
3rd number:
MID(B1,FIND(",",B1,FIND(",",B1,FIND(",",B1)+1))+1,100)
I have a column of Text Strings. Some of them have ASCII Characters greater than Char(127). I'd like to have a formula in the column next to it that will search the first column for any characters either in a range of ASCII characters or greater than Char(127). If it finds one that I'd like it to simply display "found" otherwise be left blank.
Is there a formula that would do this?
Assuming your text strings start in A1, use the following formula and copy down:
=IF(MAX(CODE(MID(A1,ROW(OFFSET($A$1,0,0,LEN(A1),1)),1)))>127,"found","")
Validate the formula with Ctrl+Shift+Enter as it is an array formula.
Example, for the word apple. I want the output to be
apple
a.pple
a.p.ple
and so on. I need to get all the possibilities. The only rule is it can't have two periods in a row and also no periods at the end or start.
How can I do this in excel? Even a simple .txt would be okay as well.
This can be done in Excel by using string formulas. This is what my worksheet looks like:
The formula in cell B2 is: =LEFT($A$1,A2)&"."&MID($A$1,A2+1,5)
Cell A1 has the string "apple", and cell A2 has the integer 0, B2 has the string ".apple" (which you don't want, so you can ignore this value). I drag down the column of integers in column A from 0 to 5.
The "LEFT" formula takes the leftmost characters of a string, and then i insert the period between this and the following characters which are brought in using the MID formula. Since the input for LEFT and MID is the integer value in column A, this will output in column B every such combination you are looking for. Note you MUST lock cell A1 in this formula, as the string will always be in cell A1.
Hope this helps!