TextJoin Function

Kathryn_Marie

New Member
Joined
Feb 3, 2020
Messages
8
Office Version
  1. 365
Platform
  1. Windows
Hi All,
I need to create a folder path from a raw data source which will update often. The data is on this format:

Material (SAP L.1-5 Functional Process Hierarchy)
_Simulation Guide
_eLearning Guide
_Title Page
_Audience and Prerequisites
_Housekeeping
_Topics
Topic 1 - <Title>
_Topic
_Objectives
_Introduction
_Simulation - <Title>
_Conclusion

I have used this formula which almost works, but it keeps adding previous entries from the same column which I do not want. Wondering is anyone may know how I can use this formula till it finds an entry, then starts again, or if there is another way to do this. This is what I have which gives the result below:

=TEXTJOIN("/", TRUE, E$2:E2, F$2:F2, G$2:G2, H$2:H2, I$2:I2, J$2:J2)

Content
Content/Material (SAP L.1-5 Functional Process Hierarchy)
Content/Material (SAP L.1-5 Functional Process Hierarchy)/_Simulation Guide
Content/Material (SAP L.1-5 Functional Process Hierarchy)/_Simulation Guide/_eLearning Guide
Content/Material (SAP L.1-5 Functional Process Hierarchy)/_Simulation Guide/_eLearning Guide/_Title Page
Content/Material (SAP L.1-5 Functional Process Hierarchy)/_Simulation Guide/_eLearning Guide/_Title Page/_Audience and Prerequisites
Content/Material (SAP L.1-5 Functional Process Hierarchy)/_Simulation Guide/_eLearning Guide/_Title Page/_Audience and Prerequisites/_Housekeeping
Content/Material (SAP L.1-5 Functional Process Hierarchy)/_Simulation Guide/_eLearning Guide/_Title Page/_Audience and Prerequisites/_Housekeeping/_Topics
Content/Material (SAP L.1-5 Functional Process Hierarchy)/_Simulation Guide/_eLearning Guide/_Title Page/_Audience and Prerequisites/_Housekeeping/_Topics/Topic 1 - <Title>
Content/Material (SAP L.1-5 Functional Process Hierarchy)/_Simulation Guide/_eLearning Guide/_Title Page/_Audience and Prerequisites/_Housekeeping/_Topics/Topic 1 - <Title>/_Topic
Content/Material (SAP L.1-5 Functional Process Hierarchy)/_Simulation Guide/_eLearning Guide/_Title Page/_Audience and Prerequisites/_Housekeeping/_Topics/Topic 1 - <Title>/_Topic/_Objectives
Content/Material (SAP L.1-5 Functional Process Hierarchy)/_Simulation Guide/_eLearning Guide/_Title Page/_Audience and Prerequisites/_Housekeeping/_Topics/Topic 1 - <Title>/_Topic/_Objectives/_Introduction
Content/Material (SAP L.1-5 Functional Process Hierarchy)/_Simulation Guide/_eLearning Guide/_Title Page/_Audience and Prerequisites/_Housekeeping/_Topics/Topic 1 - <Title>/_Topic/_Objectives/_Introduction/_Simulation - <Title>
Content/Material (SAP L.1-5 Functional Process Hierarchy)/_Simulation Guide/_eLearning Guide/_Title Page/_Audience and Prerequisites/_Housekeeping/_Topics/Topic 1 - <Title>/_Conclusion/_Topic/_Objectives/_Introduction/_Simulation - <Title>
Content/Material (SAP L.1-5 Functional Process Hierarchy)/_Simulation Guide/_eLearning Guide/_Quiz Guide/_Title Page/_Audience and Prerequisites/_Housekeeping/_Topics/Topic 1 - <Title>/_Conclusion/_Topic/_Objectives/_Introduction/_Simulation - <Title>
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
You'd need to keep referencing the last value in each column.
Try something like this ugly regular formula:
=TEXTJOIN("\",TRUE,IFERROR(LOOKUP("ZZZZZZ",D$2:D2),""),IFERROR(LOOKUP("ZZZZZZ",E$2:E2),"")
,IFERROR(LOOKUP("ZZZZZZ",F$2:F2),""),IFERROR(LOOKUP("ZZZZZZ",G$2:G2),""),IFERROR(LOOKUP("ZZZZZZ",H$2:H2),""))
 
Upvote 0
Not quite Ron, from the last 3 rows in my example, the results I get are this:

Content\Material (SAP L.1-5 Functional Process Hierarchy)\_eLearning Guide\Topic 1 - <Title>\_Simulation - <Title>
Content\Material (SAP L.1-5 Functional Process Hierarchy)\_eLearning Guide\_Conclusion\_Simulation - <Title>
Content\Material (SAP L.1-5 Functional Process Hierarchy)\_Quiz Guide\_Conclusion\_Simulation - <Title>

So it is going forwards perfectly, but when the folder structure is one less, it continues to put in the values from the next columns from previous :/
 
Upvote 0
OK...Let's see if this works. It requires some of the latest updates to O365 (which you indicate you are using):
(Side note: Building this was great fun)
I2: =TEXTJOIN("|",TRUE,CHOOSE(SEQUENCE(1,XLOOKUP("?*",D2:H2,{1,2,3,4,5},0,2,-1)),CONCAT(D$2:D2),CONCAT(E$2:E2),CONCAT(F$2:F2),CONCAT(G$2:G2),CONCAT(H$2:H2)))

(Edited to shorten it a bit)

Copy I2 down through I15.

Is that something you can work with?
 
Last edited:
Upvote 0
It still seems to be giving duplicates of the items above it :/

Material (SAP L.1-5 Functional Process Hierarchy)/_Simulation Guide_eLearning Guide_Quiz GuideCross Functional Elements (CFE)
Material (SAP L.1-5 Functional Process Hierarchy)/_Simulation Guide_eLearning Guide_Quiz GuideCross Functional Elements (CFE)/_Title Page_Audience and Prerequisites_Housekeeping_TopicsTopic 1 - <Title>_ConclusionApplication Basics (AB)
Material (SAP L.1-5 Functional Process Hierarchy)/_Simulation Guide_eLearning Guide_Quiz GuideCross Functional Elements (CFE)/_Title Page_Audience and Prerequisites_Housekeeping_TopicsTopic 1 - <Title>_ConclusionApplication Basics (AB)Basis Components (BC)
Material (SAP L.1-5 Functional Process Hierarchy)/_Simulation Guide_eLearning Guide_Quiz GuideCross Functional Elements (CFE)/_Title Page_Audience and Prerequisites_Housekeeping_TopicsTopic 1 - <Title>_ConclusionApplication Basics (AB)Basis Components (BC)Business Warehouse (BW)
Material (SAP L.1-5 Functional Process Hierarchy)/_Simulation Guide_eLearning Guide_Quiz GuideCross Functional Elements (CFE)/_Title Page_Audience and Prerequisites_Housekeeping_TopicsTopic 1 - <Title>_ConclusionApplication Basics (AB)Basis Components (BC)Business Warehouse (BW)Environment, Health & Safety (EHS)
Material (SAP L.1-5 Functional Process Hierarchy)/_Simulation Guide_eLearning Guide_Quiz GuideCross Functional Elements (CFE)/_Title Page_Audience and Prerequisites_Housekeeping_TopicsTopic 1 - <Title>_ConclusionApplication Basics (AB)Basis Components (BC)Business Warehouse (BW)Environment, Health & Safety (EHS)Governance, Risk & Compliance (GRC)
Material (SAP L.1-5 Functional Process Hierarchy)/_Simulation Guide_eLearning Guide_Quiz GuideCross Functional Elements (CFE)/_Title Page_Audience and Prerequisites_Housekeeping_TopicsTopic 1 - <Title>_ConclusionApplication Basics (AB)Basis Components (BC)Business Warehouse (BW)Environment, Health & Safety (EHS)Governance, Risk & Compliance (GRC)Knowledge Management (KM)
Material (SAP L.1-5 Functional Process Hierarchy)/_Simulation Guide_eLearning Guide_Quiz GuideCross Functional Elements (CFE)Customer Relationship Management (CRM)
 
Upvote 0
Hi, Kathryn_Marie. Welcome to the Forum.

This is what I have which gives the result below:

=TEXTJOIN("/", TRUE, E$2:E2, F$2:F2, G$2:G2, H$2:H2, I$2:I2, J$2:J2)

It doesn't clear to me.
The second table in post #1, is that the result that you want or the result when you use your formula?
If it is the result when you use your formula, then can you show us the result that you want?
 
Upvote 0
That's the result I am getting, the result I want would be:

Material (SAP L.1-5 Functional Process Hierarchy)/_Simulation Guide
Material (SAP L.1-5 Functional Process Hierarchy)/_eLearning Guide
Material (SAP L.1-5 Functional Process Hierarchy)/_eLearning Guide/_Title Page
Material (SAP L.1-5 Functional Process Hierarchy)/_eLearning Guide/_Audience and Prerequisites
Material (SAP L.1-5 Functional Process Hierarchy)/_eLearning Guide/_Housekeeping
Material (SAP L.1-5 Functional Process Hierarchy)/_eLearning Guide/_Topics
Material (SAP L.1-5 Functional Process Hierarchy)/_eLearning Guide/Topic 1 - <Title>
Material (SAP L.1-5 Functional Process Hierarchy)/_eLearning Guide/Topic 1 - <Title>/_Topic
Material (SAP L.1-5 Functional Process Hierarchy)/_eLearning Guide/Topic 1 - <Title>/_Objectives
Material (SAP L.1-5 Functional Process Hierarchy)/_eLearning Guide/Topic 1 - <Title>/_Introduction
Material (SAP L.1-5 Functional Process Hierarchy)/_eLearning Guide/Topic 1 - <Title>/_Simulation - <Title>
Material (SAP L.1-5 Functional Process Hierarchy)/_eLearning Guide/_Conclusion

From this:

Material (SAP L.1-5 Functional Process Hierarchy)
_Simulation Guide
_eLearning Guide
_Title Page
_Audience and Prerequisites
_Housekeeping
_Topics
Topic 1 - <Title>
_Topic
_Objectives
_Introduction
_Simulation - <Title>
_Conclusion
 
Upvote 0
Try this code. It will insert the blank cells with correct data. After that you can easily use TextJoin formula to get the result.
VBA Code:
Sub a1122849a()
'https://www.mrexcel.com/board/threads/textjoin-function.1122849
Dim a As Long, b As Long
a = ActiveSheet.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
b = ActiveSheet.Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
    With Range(Cells(2, "A"), Cells(a, b))
        .SpecialCells(xlBlanks).FormulaR1C1 = "=IF(RC[1]<>"""",R[-1]C,"""")"
       .Value = .Value
    End With

End Sub
EXAMPLE:
Book1
ABCD
1test
2_Simulation Guide
3_eLearning Guide
4_Title Page
5_Audience and Prerequisites
6_Housekeeping
7_Topics
8Topic 1 - <Title>
9_Topic
10_Objectives
11_Introduction
12_Simulation - <Title>
13_Conclusion
14xx
15yy
16zz
Sheet8


RESULT:
Book1
ABCD
1test
2test_Simulation Guide
3test_eLearning Guide
4test_eLearning Guide_Title Page
5test_eLearning Guide_Audience and Prerequisites
6test_eLearning Guide_Housekeeping
7test_eLearning Guide_Topics
8test_eLearning GuideTopic 1 - <Title>
9test_eLearning GuideTopic 1 - <Title>_Topic
10test_eLearning GuideTopic 1 - <Title>_Objectives
11test_eLearning GuideTopic 1 - <Title>_Introduction
12test_eLearning GuideTopic 1 - <Title>_Simulation - <Title>
13test_eLearning Guide_Conclusion
14testxx
15testxxyy
16testxxyyzz
Sheet9
 
Upvote 0
That worked well thanks. I had to remove zeros in the cells where there was no column name, and if I put in a column name it duplicated that instead of leaving blank cells, but that's no biggie :)
 
Upvote 0

Forum statistics

Threads
1,214,588
Messages
6,120,409
Members
448,959
Latest member
camelliaCase

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