extract the header of sets of non empty cell

ExcelNewbie2020

Active Member
Joined
Dec 3, 2020
Messages
343
Office Version
  1. 365
Platform
  1. Windows
Sirs,

I would like to extract the header of non empty cell. if there are more than 1 set empty cell, i need it textjoin.
also i need to textjoin the 1st and last non blank cell of each sets..please see column K for the result..

Book1
ABCDEFGHIJK
2ABCEFGHIJRESULT
3XXXXXXXA-C,F-G,I-J
4XXXXA-B,D-E
5XXC-D
Sheet2



Many Thanks,
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Try in K2 and copy down:

Excel Formula:
=TEXTJOIN(",",,BYROW(TEXTSPLIT(TEXTJOIN("",,SUBSTITUTE(IF(A2:I2="",",",A2:I2),"X",A$1:I$1)),,","),LAMBDA(br,IF(LEN(br)>1,LEFT(br)&"-"&RIGHT(br),br))))
 
Upvote 0
I assume that the headers are not letters and can be any text, in such case:

Excel Formula:
=TEXTJOIN(",",1,SUBSTITUTE(BYROW(TEXTSPLIT("|"&TEXTJOIN("|",,IF(A2:I2="",",",A$1:I$1))&"|",,","),LAMBDA(br,IF(LEN(br)-LEN(SUBSTITUTE(br,"|",""))>2,MID(br,1,SEARCH("|",br,2)-1)&"-"&TRIM(RIGHT(SUBSTITUTE(br,"|",REPT(" ",99)),198)),br))),"|",""))
 
Upvote 0
Solution
I assume that the headers are not letters and can be any text, in such case:

Excel Formula:
=TEXTJOIN(",",1,SUBSTITUTE(BYROW(TEXTSPLIT("|"&TEXTJOIN("|",,IF(A2:I2="",",",A$1:I$1))&"|",,","),LAMBDA(br,IF(LEN(br)-LEN(SUBSTITUTE(br,"|",""))>2,MID(br,1,SEARCH("|",br,2)-1)&"-"&TRIM(RIGHT(SUBSTITUTE(br,"|",REPT(" ",99)),198)),br))),"|",""))
thanks man..
 
Upvote 1

Forum statistics

Threads
1,223,886
Messages
6,175,190
Members
452,616
Latest member
intern444

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