Cocatenating two columns of text into a third

petergr

New Member
Joined
Feb 1, 2012
Messages
4
This should be easy, I have a column of First Names, a column of second names and I wish to create a new column with First Name , space, Last name.

I can create a cell specific code such as
= CONCATENATE(B2," ",C2)

However I want to make this into a macro to run on any file that I open for every entry in the columns (I export a file weekly and need to run it each time).

My macro and VBA skills are very basic!

Thanks for your help.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Assuming always concatenate columns B and C with results in column D, try

Code:
Sub concat()
Dim LR As Long
LR = Range("B" & Rows.Count).End(xlUp).Row
Range("D2:D" & LR).Formula = "= CONCATENATE(B2,"" "",C2)"
End Sub
 
Upvote 0
Welcome to the board.

Assuming your two columns are A and B, that row 1 is the header row (so your data starts in row 2) and you want to concatenate into C, try:
Code:
Sub Concatenate()
Dim i as Long
 
Application.ScreenUpdating = False
 
i = Range("A" & Rows.Count).End(xlUp).Row
Range("C2:C" & i).Formula = "=A2" & "" "" & "B2"
 
Application.ScreenUpdating = True
 
End Sub
 
Upvote 0
Thanks for your help, I will try this tonight. Thanks for being very specific with the references - it is a big help to newbies like me!

Peter
 
Upvote 0
Re: Concatenating two columns of text into a third

Thanks VoG, unfortunately your code produced an error in each cell and I wasnt clever enough to debug it. JackDanIce your code worked straight away.

Thanks for helping me out.

Peter
 
Upvote 0
Only difference between VoG's code and mine are the columns we reference - mine looks at A and B to create your output in C, VoG's looks at B and C to place output into D. The letters in red refer to column letters:
Rich (BB code):
Sub Concatenate()
Dim i as Long
 
Application.ScreenUpdating = False
 
' This line finds the last row in column A that has a value in it
i = Range("A" & Rows.Count).End(xlUp).Row
 
' This line is put a formula into every row in column C between rows 2 and
' The last used row that we found in column A
' The formula combines what is in column A with a space and then what is in column B
' Using "&" is another way of saying "Concatenate
' In VBA code, spaces have to be surrounded by a pair of speach marks
Range("C2:C" & i).Formula = "=A2" & "" "" & "B2"
 
Application.ScreenUpdating = True
 
End Sub
 
Upvote 0
Re: Concatenating two columns of text into a third

Sorry JackDanIce I did transpose the approprate columns, but I am sure it was my error somewhere! As I said, my skills are pretty basic.

Thanks again
 
Upvote 0
No worries, was just to help you understand my code and show VoG had his correct too - it works now anyway!
 
Upvote 0

Forum statistics

Threads
1,216,124
Messages
6,128,991
Members
449,480
Latest member
yesitisasport

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