Error in Custom Function Since moving to Excel 2019

scottb
4StarLounger
Posts: 402
Joined: 14 Apr 2010, 15:59

Error in Custom Function Since moving to Excel 2019

Post by scottb »

Hi everyone.
Hans, a while back you built a function for me that would concatenate a listed column range and place it in the current cell, separated by commas.

Code: Select all

Function ConcatCells(rng As Range) As String
    Dim cel As Range
    Dim retVal As String
    For Each cel In rng
        retVal = retVal & ", " & cel.Text
    Next cel
    If retVal <> "" Then
        ConcatCells = Mid(retVal, 3)
    End If
End Function
My work computer was upgraded to MS Office 2019 (32 bit).
The function still runs however it no longer separates the column values with a comma and a space. It just strings everything together.
Any idea why and how to resolve?
Thank you for your help!
-Scott

User avatar
HansV
Administrator
Posts: 78481
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Error in Custom Function Since moving to Excel 2019

Post by HansV »

That's strange. It still works correctly for me in Excel 2019.

But you don't need this function anymore - Excel 2019 has a new built-in function TEXTJOIN. The formula

=TEXTJOIN(", ",TRUE, A1:A4)

can be used instead of

=ConcatCells(A1:A4)

S0466.png
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

scottb
4StarLounger
Posts: 402
Joined: 14 Apr 2010, 15:59

Re: Error in Custom Function Since moving to Excel 2019

Post by scottb »

Hi Hans,
TextJoin does the trick.
Thank you as always for your help.
-Scott

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15619
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Error in Custom Function Since moving to Excel 2019

Post by ChrisGreaves »

HansV wrote:
01 Jun 2021, 07:00
TEXTJOIN. ...
And all over the world people lose hours of work time and sleep over why their budget spreadsheet has stopped working.

Or worse: They don't realize that this year's budget spreadsheet isn't working correctly!
I continue to be puzzled at MS's inability to cause such changes to go unannounced to the end-user.
I know that KB articles are published, but a #REF or #ERR or even a #UPGRADE in a budget spreadsheet would do wonders for the Bottom Line!

Cheers
Chris
There's nothing heavier than an empty water bottle

scottb
4StarLounger
Posts: 402
Joined: 14 Apr 2010, 15:59

Re: Error in Custom Function Since moving to Excel 2019

Post by scottb »

Chris,
I was thinking about the very topic you described. Ugh....Good fun.
Be well everyone.