Macro To Combine Rows Into 1 through unknown # of rows

gmercer82

New Member
Joined
May 14, 2012
Messages
37
I would like to have a macro that will take all of the rows in Column A and combine them into cell B2. Normally in excel I would just do A1&A2&A3...

Information Example:
St Louis
Chicago
Boston

In cell B2 I would like it to look like
St LouisChicagoBoston

I was able to get a formula that will run it through the number of rows that will have something. I just need to code for the space listed as [needed formula].

Dim WS As Worksheet
Dim LastRow As Long
Set WS = ActiveSheet
With WS
LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
For A = 1 To LastRow

[needed formula]

Next
End With
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Try this:
Code:
Dim WS As Worksheet
Dim LastRow As Long
Dim myValue as String

 
Set WS = ActiveSheet
With WS
    LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
    For A = 1 To LastRow
        myValue=myValue & Cells(A,1)
    Next A
    Range("B2")=myValue
End With
 
Upvote 0
try this

Code:
Sub CombineDataA()
Dim LR As Long, i As Long
Dim CData As String
LR = ActiveSheet.Range("C" & Rows.Count).End(xlUp).Row
For i = 2 To LR
    If i = 2 Then
        CData = Cells(i, "A")
    End If
    If i > 2 Then
        CData = CData & Cells(i, "A")
    End If
Next i
Range("B2") = CData
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,234
Messages
6,054,284
Members
444,715
Latest member
GlitchHawk

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