concatenate in vba

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi
I am trying to concatenate the first 10 cells in A, and B columns and put them in C. So I did this program which did not work. Any help would be very much apprecaited.

Sub concat()
Dim i As Integer, j As Integer
For i = 1 To 10
For j = 1 To 10
Cells(i, j + 2).Value = Cells(i, j).Value & Cells(i, j + 1).Value
Next i
Next j
End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Are you trying to concatenate A1 & B1 & put the result in C1?
If not please clearly explain what you want, rather than posting non-working code & rely on us to guess.
 
Upvote 0
You only need one loop here:

Code:
Sub concat()
Dim i As Integer
For i = 1 To 10
Cells(i, 3).Value = Cells(i, 1).Value & Cells(i, 2).Value
Next
End Sub
 
Last edited:
Upvote 0
Not as proper, but a one line version:

Code:
Sub concat()
Range("c1").Resize(10).Value = Evaluate(Range("a1").Resize(10).Address & "&" & Range("b1").Resize(10).Address)
End Sub
 
Upvote 0
Yes exactly. Thank you.

Are you trying to concatenate A1 & B1 & put the result in C1?
If not please clearly explain what you want, rather than posting non-working code & rely on us to guess.
 
Upvote 0
Have you tried either of the codes supplied by sheetspread?
Just for the sake of it, here's another option
Code:
Sub myConcat()
   Dim Cl As Range
   For Each Cl In Range("A1:A10")
   Cl.Offset(, 2).Value = Join(Application.Index(Cl.Resize(, 2).Value, 1, 0), "")
   Next Cl
End Sub
 
Upvote 0
Thank you all for the help. I need more time to understand the code and many things are new to me i.e Join, Index, offset.. I thought it is easier than this. I think I am not ready for it now. I will try to understand your code. Thank you so much once again
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0
I just saw this one. I thought that was my code. Now I understand it perfectly.
Thank you so much to all of you.

You only need one loop here:

Code:
Sub concat()
Dim i As Integer
For i = 1 To 10
Cells(i, 3).Value = Cells(i, 1).Value & Cells(i, 2).Value
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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