VBA: concatenate data

azov5

New Member
Joined
Dec 27, 2018
Messages
40
I have data in Column A1:A100 and B1:B100.
I need to Concatenate data in C column so that column A data appears below column B data in respective cell.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Not clear to me what you want. Can you post a small sample of the data and how it would look after the VBA is executed?
 
Upvote 0
Say if cell A2 is "where am I" and cell B2 data is "I am in USA" then the result in C2 will be

I am in USA
where am I

And this will follow up to C100
 
Upvote 0
Try this:
Code:
Sub ConcatAandBinC()
Dim LRw As Long
LRw = Cells(Rows.Count, "A").End(xlUp).Row
Application.ScreenUpdating = False
With Range("C1:C" & LRw)
    .Formula = "=B1&CHAR(10)&A1"
    .Value = .Value
    .EntireColumn.AutoFit
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Since you indicated A1:A100 and B1:B100 all had data in them, this macro should work for you...
Code:
Sub ConcatAandB()
  [C1:C100] = [A1:A100&CHAR(10)&B1:B100]
End Sub
If the cells will not be filled down all the way to 100, then give this a try instead...
Code:
Sub ConcatAandB()
  Dim LastRow As Long
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  Range("C1:C" & LastRow) = Evaluate(Replace("A1:A#&CHAR(10)&B1:B#", "#", LastRow))
End Sub
 
Last edited:
Upvote 0
Since you indicated A1:A100 and B1:B100 all had data in them, this macro should work for you...
Code:
Sub ConcatAandB()
  [C1:C100] = [[COLOR=#ff0000][B]A1:A100&CHAR(10)&B1:B100[/B][/COLOR]]
End Sub
If the cells will not be filled down all the way to 100, then give this a try instead...
Code:
Sub ConcatAandB()
  Dim LastRow As Long
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  Range("C1:C" & LastRow) = Evaluate(Replace("A1:A#&CHAR(10)&B1:B#", "#", LastRow))
End Sub
Rick, OP indicated he wants B-cell text above A-cell text.
 
Upvote 0
Rick, OP indicated he wants B-cell text above A-cell text.
Yikes! I completely missed that. :oops: Thanks for pointing that out.

Simple fix though...

Since you indicated A1:A100 and B1:B100 all had data in them, this macro should work for you...
Code:
Sub ConcatAandB()
  [C1:C100] = [B1:B100&CHAR(10)&A1:A100]
End Sub
If the cells will not be filled down all the way to 100, then give this a try instead...
Code:
Sub ConcatAandB()
  Dim LastRow As Long
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  Range("C1:C" & LastRow) = Evaluate(Replace("B1:B#&CHAR(10)&A1:A#", "#", LastRow))
End Sub
 
Last edited:
Upvote 0
And if I want to do the opposite i.e, the original again !
Do you mean put the A-cell text above the B-cell text? If so, just swap A for B. In the code I posted it would be this line:

.Formula = "=B1&CHAR(10)&A1"

is changed to this:

.Formula = "=A1&CHAR(10)&B1"
 
Upvote 0

Forum statistics

Threads
1,213,517
Messages
6,114,085
Members
448,548
Latest member
harryls

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