Forum

VBA; Textjoin funct...
 
Notifications
Clear all

VBA; Textjoin function not joining cell

2 Posts
1 Users
0 Reactions
480 Views
(@darkwing1711)
Posts: 31
Trusted Member
Topic starter
 

Hi all!

I'm trying to use TEXTJOIN in VBA.  For the most part it's working but it's not joining everything.  At first, I thought perhaps the format is incorrect.  I made sure it was all text, but no luck.  Looking at my result table, it's not consistent with the format that it joins.  I don't think it's that.

or if you have a better idea, let me know!

Thanks in advance!

PS.  I prefer using TEXTJOIN because of the delimiter and skipping blanks so that it doesn't add extra spaces, as CONCAT would do.

 

Data is below

Pgm:   ZPPR_INV_REFERRAL_SUMM
Tcode:   ZPPIRS
Date:   02/08/2021
Time:   12:34:13

Blow is my result

RED: Data not joining

GREEN: Data joined

Pgm:   ZPPR_INV_REFERRAL_SUMM
Tcode: ZPPIRS   ZPPIRS
Date:   02/08/2021
Time: 12:34:13   12:34:13

Below is my code

Sub textjoin()

Dim csmp As Worksheet
Set csmp = Sheet1

Dim col1 As Range
Set col1 = csmp.Range("t_csmp[Column1]")

'Merge Column 1
     Dim cell As Range
     nextrow = 2

For Each cell In col1
     cell(nextrow, 1).Value = WorksheetFunction.textjoin(" ", True, cell(nextrow, 1), cell(nextrow, 2), cell(nextrow, 3))
     nextrow = nextrow + 1
Next cell

End Sub

 
Posted : 12/02/2021 1:20 pm
(@darkwing1711)
Posts: 31
Trusted Member
Topic starter
 

I got it!  Nevermind!  Theissue in my code was

cell(nextrow, 1).Value = WorksheetFunction.textjoin(" ", True, cell(nextrow, 1), cell(nextrow, 2), cell(nextrow, 3))

I changed it to 

cell = WorksheetFunction.textjoin(" ", True, cell(nextrow, 1), cell(nextrow, 2), cell(nextrow, 3))

Now its working.  Duh! lol thank you anyways!

 
Posted : 12/02/2021 1:34 pm
Share: