TEXTJOIN alternative for older versions?

adams2712

New Member
Joined
Aug 2, 2022
Messages
3
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
Hi all, new poster but at my wits end with TEXTJOIN function. I created a spreadsheet for staffing and had it functioning at home in Office 365 using the TEXTJOIN function, however my systems at work use Office 2013 in most workstations, so my command stopped working. My command is as follows:
=TEXTJOIN(",",TRUE,IF(A6=B2:B27,A2:A23,""))

This provides a return of all staff names marked with either a "D" or an "N" in that day's column (I have placed a hidden "D" and "N" in cells A6 and A9 of the sheet to provide a reference value).
I was wondering if there was an easy way outside of VBA for this to be achieved using backwards compatible functions? See screenshots below for examples of the code working and the code broken in 2013.
 

Attachments

  • 365 screenshot.png
    365 screenshot.png
    64 KB · Views: 12
  • 2013 screenshot.jpg
    2013 screenshot.jpg
    156.2 KB · Views: 13

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hi & welcome to MrExcel.
You could use something like
Excel Formula:
=MID(IF(B2=A6,","&A2,"")&IF(B3=A6,","&A3,"")&IF(B4=A6,","&A4,""),2,1000)
 
Upvote 0
T
Hi & welcome to MrExcel.
You could use something like
Excel Formula:
=MID(IF(B2=A6,","&A2,"")&IF(B3=A6,","&A3,"")&IF(B4=A6,","&A4,""),2,1000)
Thanks for the reply, my full sheet has 27 staff members, the screenshot is of the senior nurses section only, I assume this code could be expanded with extra IF functions to encompass the whole staffing section?
 
Upvote 0
I assume this code could be expanded with extra IF functions to encompass the whole staffing section?
That's right, I only did the 1st 3 to show the general construct.
 
Upvote 0
Managed t
That's right, I only did the 1st 3 to show the general construct.
Managed to get it to work on new rows, code will be very long, but i think its going to work, thanks again :)
 
Upvote 0
My command is as follows:
=TEXTJOIN(",",TRUE,IF(A6=B2:B27,A2:A23,""))
Are you sure that is your formula? Your ranges (B2:B27 and A2:A23) are different sizes. That means that if, say, B26 = A6 then the formula would return a #N/A error because there is no corresponding value in your column A range.

Assuming that your ranges are the same size then another option to save such a long formula might be to employ a user-defined function.
Here is one you could try. I have built-in the 'ignore empty cells' setting as I assumed you would never want an empty cell returned in the results
I have also hard-coded the comma delimiter but that could also be an argument of the function if required.

If you are interested in trying this approach then to implement ..
1. Right click the sheet name tab and choose "View Code".
2. In the Visual Basic window use the menu to Insert|Module
3. Copy and Paste the code below (you can use the icon at the top right of the code pane below) into the main right hand pane that opens at step 2.
4. Close the Visual Basic window.
5. Enter the formula as shown in the screen shot below.
6. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm)

VBA Code:
Function TJ(delim As String, str As String, strFoundInRng As Range, ResultRng As Range) As String
  Dim i As Long
  
  For i = 1 To strFoundInRng.Count
    If UCase(strFoundInRng.Cells(i).Value) = UCase(str) Then TJ = TJ & "," & ResultRng.Cells(i).Value
  Next i
  TJ = Mid(TJ, 2)
End Function

adams2712.xlsm
ABCD
1
2aaa
3bbbaa,dd,ee,gg,jj
4ccx
5a
6dda
7eea
8ffj
9gga
10hh
11a
12jja
13
Sheet1
Cell Formulas
RangeFormula
D3D3=TJ(",",A5,B2:B23,A2:A23)
 
Upvote 0

Forum statistics

Threads
1,215,036
Messages
6,122,794
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top