Reputation: 59
I'm trying to take a column of data that contains either course information (with text), or just the number 0, and string together the values that do NOT equal 0 from that column into ONLY one cell on another tab.
Ex:
[*COLUMN A*] COURSE B8001 COURSE B8002 0 0 COURSE B8003
^ I want to take this column...
and turn it into this...
Cell 1: COURSE B8001, COURSE B8002, COURSE B8003
(all under the same column, just in one cell)
I have been using the concatenate and if functions to no avail and am stuck.
Appreciate any help
Upvotes: 0
Views: 69
Reputation: 152660
If you have Office 365 Excel then you can use this array formula:
=TEXTJOIN(",",TRUE,IF(A1:A100<>0,A1:A100,""))
Being an array formula it would need to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting Edit mode
If you do not have OFFICE 365 Excel then you will need a helper column or vba.
Helper, Put this in B1 and drag the length of the data:
=IF(A1<>0,A1&","&B2,B2)
And your concatenated statement will appear in B1
vba, Put this in a module attached to the workbook:
Function TEXTJOINIFS(rng As Range, delim As String, ParamArray arr() As Variant)
Dim rngarr As Variant
rngarr = Intersect(rng, rng.Parent.UsedRange).Value
Dim condArr() As Boolean
ReDim condArr(1 To Intersect(rng, rng.Parent.UsedRange).Rows.Count) As Boolean
Dim i As Long
For i = LBound(arr) To UBound(arr) Step 2
Dim colArr() As Variant
colArr = Intersect(arr(i), arr(i).Parent.UsedRange).Value
Dim j As Long
For j = LBound(colArr, 1) To UBound(colArr, 1)
If Not condArr(j) Then
Dim charind As Long
charind = Application.Max(InStr(arr(i + 1), ">"), InStr(arr(i + 1), "<"), InStr(arr(i + 1), "="))
Dim opprnd As String
If charind = 0 Then
opprnd = "="
Else
opprnd = Left(arr(i + 1), charind)
End If
Dim t As String
t = """" & colArr(j, 1) & """" & opprnd & """" & Mid(arr(i + 1), charind + 1) & """"
If Not Application.Evaluate(t) Then condArr(j) = True
End If
Next j
Next i
For i = LBound(rngarr, 1) To UBound(rngarr, 1)
If Not condArr(i) Then
TEXTJOINIFS = TEXTJOINIFS & rngarr(i, 1) & delim
End If
Next i
TEXTJOINIFS = Left(TEXTJOINIFS, Len(TEXTJOINIFS) - Len(delim))
End Function
Then call it like SUMIFS:
=TEXTJOINIFS(A:A,",",A:A,"<>0")
Upvotes: 1