Textjoin question

Holley

Board Regular
Joined
Dec 11, 2019
Messages
120
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have tweaked Fluff's code to use Textjoin a column in vba. Everything works beautifully, except I a getting a "," when there are blank cells. If there is no data, I need for the cells to remain blank.
VBA Code:
Sub textjoin()
   With Range("AI2:AI" & Range("A" & Rows.Count).End(xlUp).Row)
   .Formula = "=TEXTJOIN("","",TRUE,AE2:AH2)"
      .Value = .Value
   End With
  End Sub
1688148610935.png

When I use the formula that provides the desired results directly in the spreadsheet, I get a Run-Time 1004 error
VBA Code:
Sub textjoin()
   With Range("AI2:AI" & Range("A" & Rows.Count).End(xlUp).Row)
   .Formula = "=TEXTJOIN("",TRUE,AE2:AH2)"
      .Value = .Value
   End With
  End Sub
1688148656310.png

Any suggestions on preventing this would be most appreciated!!
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
I am not 100% sure of why you have TRUE in there, but see if changing this line...

.Formula = "=TEXTJOIN("",TRUE,AE2:AH2)"

to this...

.Formula = "=TEXTJOIN("""","""",,AE2:AH2)"

does what you want.
 
Upvote 0
Thanks for your quick reply! I was thinking the TRUE was to skip the empty cells. I did try this, but I received a "VALUE! error on each of the rows

VBA Code:
Sub textjoin()
   With Range("AI2:AI" & Range("A" & Rows.Count).End(xlUp).Row)
   .Formula = "=TEXTJOIN("""","""",AE2:AH2)"
      .Value = .Value
   End With
  End Sub
 
Upvote 0
Try either of these:
Rich (BB code):
Sub textjoin()
   With Range("AI2:AI" & Range("A" & Rows.Count).End(xlUp).Row)
   .Formula = "=TEXTJOIN("""",,AE2:AH2)"            ' Nothing in the True/False position
   ' OR
   ' .Formula = "=TEXTJOIN("""",TRUE,AE2:AH2)"  ' Alternative
      .Value = .Value
   End With
  End Sub
 
Upvote 0
Solution
thanks for all the feedback! I kept working with it and was able to get it to work using the below code: I only needed to add a space between the two quotations.

VBA Code:
Sub textjoin()
   With Range("AI2:AI" & Range("A" & Rows.Count).End(xlUp).Row)
   .Formula = "=TEXTJOIN("" "",True,AE2:AH2)"
   .Value = .Value
   End With
  End Sub

I do appreciate all of the help!!
 
Upvote 0

Forum statistics

Threads
1,215,165
Messages
6,123,387
Members
449,098
Latest member
ArturS75

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