OFFSET and CONCATENATEMULTIPLE: can they be used together?

itr674

Well-known Member
Joined
Apr 10, 2002
Messages
1,786
Office Version
  1. 2016
Platform
  1. Windows
Can OFFSET be added to CONCATENATEMULTIPLE so the range will change accordingly as the formula is copied down the rows?

I am using UDF CONCATENATEMULTIPLE to combine text that in a range of cells to sentences in a single cell.

Using UDF CONCATENATEMULTIPLE to get a range of cells into one single cell.
IF(B2<>1,"",CONCATENATEMULTIPLE(C$2:C$3,""))

Then using SUBSTITUTE to add a carriage return and "*" at the beginning of each sentence.
SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($E2,".","."&CHAR(10)&"* ",1),
".","."&CHAR(10)&"* ",2),".","."&CHAR(10)&"* ",3),".","."&CHAR(10)&"* ",4),".","."&CHAR(10)&"* ",5),
".","."&CHAR(10)&"* ",6),".","."&CHAR(10)&"* ",7),".","."&CHAR(10)&"* ",8),".","."&CHAR(10)&"* ",9),".","."&CHAR(10)&"* ",10),
".","."&CHAR(10)&"* ",11))
 

Attachments

  • Concat1.png
    Concat1.png
    23.6 KB · Views: 21

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Do you need to use a UDF? Newer versions of excel (2019 onward) have a native function called TEXTJOIN which will work just as well without the need for substitute.

=IF(B2=1,TEXTJOIN(CHAR(10)&"*",1,C2:INDEX(C:C,AGGREGATE(14,6,ROW(A2:A20)/(A2:A20=A2),1))),"")

With your UDF, perhaps this will work in the same way

=IF(B2<>1,"",CONCATENATEMULTIPLE(C2:INDEX(C:C,AGGREGATE(14,6,ROW(A2:A20)/(A2:A20=A2),1)),CHAR(10),"*"))

Without seeing the code for the UDF I can't say for certain what will work.
 
Upvote 0
We don't have 2019 yet, wish we did.

I your formula and got the #VALUE! error.

This is the UDF code:
Function CONCATENATEMULTIPLE(Ref As Range, Separator As String) As String
Dim Cell As Range
Dim Result As String
For Each Cell In Ref
Result = Result & Cell.Value & Separator
Next Cell
CONCATENATEMULTIPLE = Left(Result, Len(Result) - 1)
End Function
 
Upvote 0
Try this version of the formula instead, remember to array confirm it with Ctrl Shift Enter.

=IF(B2<>1,"",CONCATENATEMULTIPLE(C2:INDEX(C:C,AGGREGATE(14,6,ROW(A2:A20)/(A2:A20=A2),1)),CHAR(10)&"*"))

There is an alternative UDF that I'm more familiar with, if this version of the formula doesn't work then I'll find the code and post that one instead.
 
Upvote 0
That is very close...but I forgot to put in the criteria that I want CHAR(10) after each "." so each sentence is underneath each other...
 
Upvote 0
You did include it, I just misunderstood exactly what you were trying to do. I didn't notice that some cells only had part sentences while others had multiple sentences.

See if this is any better.

=SUBSTITUTE(IF(B2<>1,"",CONCATENATEMULTIPLE(C2:INDEX(C:C,AGGREGATE(14,6,ROW(A2:A20)/(A2:A20=A2),1)),"")),".",CHAR(10)&"*")

It's preferable if you attach examples using XL2BB (button on reply box toolbar) instead of screen captures so that we can paste the data to excel and test formulas before posting them.
 
Upvote 0
Please try at E2

=IF(B2=1,SUBSTITUTE(CONCATENATEMULTIPLE(C2:INDEX(C2:C10,MATCH(2,INDEX(1/(A2:A10=A2),)))," "),".",CHAR(10)&"*"),"")
 
Upvote 0
It's preferable if you attach examples using XL2BB (button on reply box toolbar) instead of screen captures so that we can paste the data to excel and test formulas before posting them.

I would love that, but on work computer and they are locked down...

Your last formula returns this in the first cell, notice no space between "best" and "girl",

The bestgirl won the race
 
Upvote 0

Also notice every other sentence is missing a space before the "*"
The rabbit ran
* Then stopped
*then ate some fruit
* Butthen changed the mind
*and they all lived together
 
Upvote 0
Messy data = messy formula, try

=SUBSTITUTE(TRIM(IF(B2<>1,"",CONCATENATEMULTIPLE(C2:INDEX(C:C,AGGREGATE(14,6,ROW(A2:A20)/(A2:A20=A2),1))," "))),".",CHAR(10)&"* ")

edit:- moved position of TRIM function.
 
Upvote 0

Forum statistics

Threads
1,215,256
Messages
6,123,914
Members
449,132
Latest member
Rosie14

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