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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
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,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

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