Concatenation Question

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
714
Office Version
  1. 365
Platform
  1. Windows
I have what should be a simple task. I'm trying to concatenate some cells to complete a name. I didn't have an issue before I added the middle initial to the formula, but now I'm struggling. I've searched the forum, but only see concatenation examples for First and Last names, not anything with 4 parameters that accounts for missing data (MI and/or Suffix).

The basic layout is below, with expected results. Here's the formula that I'm using, that is not working:

=IF(G3="",IF(E3="",D3&" "&F3,IF(G3="",D3&" "&E3&" "&F3,IF(E3="",D3&" "&F3&" "&G3,D3&" "&E3&" "&F3&" "&G3))))

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Column D[/TD]
[TD]Column E[/TD]
[TD]Column F[/TD]
[TD]Column G[/TD]
[TD]Column H[/TD]
[/TR]
[TR]
[TD]First[/TD]
[TD]MI[/TD]
[TD]Last[/TD]
[TD]Suffix[/TD]
[TD]Name[/TD]
[/TR]
[TR]
[TD]Tommy[/TD]
[TD]J.[/TD]
[TD]Boy[/TD]
[TD]Sr.[/TD]
[TD]Tommy J. Boy Sr.[/TD]
[/TR]
[TR]
[TD]Tommy[/TD]
[TD][/TD]
[TD]Boy[/TD]
[TD]Sr.[/TD]
[TD]Tommy Boy Sr.[/TD]
[/TR]
[TR]
[TD]Tommy[/TD]
[TD]J.[/TD]
[TD]Boy[/TD]
[TD][/TD]
[TD]Tommy J. Boy[/TD]
[/TR]
[TR]
[TD]Tommy[/TD]
[TD][/TD]
[TD]Boy[/TD]
[TD][/TD]
[TD]Tommy Boy[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Yikes. I never knew that was possible. I've always used the method in my post. This is so much easier. Time to go review what TRIM actually does. Thank you so much....again! You're 2 for 2!
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0
I tried to apply this logic to a text box on a userform and I'm not getting any results in the text box. Thoughts?

Code:
'Me.txt_Name.Value = Trim(Me.txt_First.Text & Me.txt_MI.Text & Me.txt_Last.Text & Me.txt_Suff.Text)
'Me.txt_Name.Value = Trim(Me.txt_First.Value & Me.txt_MI.Value & Me.txt_Last.Value & Me.txt_Suff.Value)
 
Upvote 0
It works for me.
Are your textboxes named correctly?
 
Upvote 0
I revalidated that they are named as listed in the code. I'm wanting the txt_Name to actually concatenate the First, MI, Last and Suff; as they're typed in the form. Not sure why neither line of code works.
 
Upvote 0
Well, I don't know that I'm actually triggering it per se. I tried both lines on the initialization of the form, as well as the code that's tied to a cmd button. In thinking through it now, the code tied to the submit button probably wouldn't take effect until the sub ends, which would be why I don't see the results in txt_Name. I was thinking it would act like a formula in a cell, and respond as text is entered in the other text boxes.
 
Upvote 0
You could do it on a doubleclick event
Code:
Private Sub txt_Name_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Me.txt_Name.Value = Trim(Me.txt_First.Value & Me.txt_MI.Value & Me.txt_Last.Value & Me.txt_Suff.Value)

End Sub
Enter the data in the txtbxs then double click on txt_Name
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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