Concatenate range of cells

philip1127

New Member
Joined
Jul 29, 2002
Messages
2
Hi - I'm trying to concatenate a range of cells, (A1:A250). Is there any way to accomplish this without typing (A1&A2&A3...&A250)? Thanks so much.

-Philip
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hi - thanks for the quick reply. I tried using the function, but I think I'm running into a problem that one cell can only hold so much data? Is that true?

The end result of this is trying to create one long text string that I can turn into a sequential file.

Thanks.
 
Upvote 0
Try the following code:
<pre>Sub ConcatenateAll()
Dim x As String, rng As Range, cel As Range
With ActiveSheet
Set rng = .Range("A1:A250")
For Each cel In rng
x = x & cel.Value
Next
.Range("B1").Value = x
End With
End Sub</pre>
 
Upvote 0
Excel's limitations are as follows (from some tech support page):

Microsoft Excel 7.0 (95)
-----------------------------------------
· Maximum Sheet Size: 16,384 rows by 256 columns
· Column Width: 0 to 255 characters
· Maximum length of cell contents (text): 255 chacters

Microsoft Excel 8.0 (97)
--------------------------------------------
· Maximum Sheet Size: 65,536 rows by 256 columns
· Column Width: 0 to 255 characters
· Maximum length of cell contents (text): 32,000 characters


Microsoft Excel 2000
--------------------------------------------
· Worksheet size: 65,536 rows by 256 columns
· Column Width: 255 characters
· Length of cell contents (text): 32,767 characters. Only 1,024 display in a cell; all 32,767 display in the formula bar.
 
Upvote 0
I used it and it works great. I altered somewhat because I needed include a separator ", ". It works but how can I change it to take off the ", " after the last cell in Range.

Sub ConcatenateAll()
Dim x As String, rng As Range, cel As Range
With ActiveSheet
Set rng = .Range("D2:D" & Range("A65536").End(xlUp).Row)
For Each cel In rng
x = x & cel.Value & ", "
Next
.Range("K1").Value = x
End With
End Sub
 
Upvote 0
ok. I researched & finally figured it out for those that may need this in the future. This code will concatenate a Range (column d in this example) with ", " & then take out the ", " on the last one. The result is provided in "K1".

Sub ConcatenateAll()
Dim x As String, rng As Range, cel As Range
Dim myString As String
With ActiveSheet
Set rng = .Range("D2:D" & Range("A65536").End(xlUp).Row)
For Each cel In rng
x = x & cel.Value & ", "
Next
.Range("K1").Value = Left(x, Len(x) - 2)
End With
End Sub
 
Upvote 0
ok. I researched & finally figured it out for those that may need this in the future. This code will concatenate a Range (column d in this example) with ", " & then take out the ", " on the last one. The result is provided in "K1".

This may be a bit late... but with a slight revision I have this working simply to remove the extra comma at the end:


Sub ConcatenateAll()
Dim x As String, rng As Range, cel As Range
Dim y As String


With ActiveSheet


Set rng = .Range("A2:A" & Range("A65536").End(xlUp).Row)


For Each cel In rng


x = x & cel.Value & ", "
y = Len(x)
Next


.Range("B1").Value = Left(x, y - 2)


End With
End Sub
 
Upvote 0
I have another suggestion which is a bit simpler

Sub ConcatenateAll()
Dim x As String, rng As Range, cel As Range

With ActiveSheet

Set rng = .Range("A2:A" & Range("A65536").End(xlUp).Row)

For Each cel In rng

x = x & ", " & cel.Value

Next

.Range("B1").Value = x


End With
End Sub


This may be a bit late... but with a slight revision I have this working simply to remove the extra comma at the end:


Sub ConcatenateAll()
Dim x As String, rng As Range, cel As Range
Dim y As String


With ActiveSheet


Set rng = .Range("A2:A" & Range("A65536").End(xlUp).Row)


For Each cel In rng


x = x & cel.Value & ", "
y = Len(x)
Next


.Range("B1").Value = Left(x, y - 2)


End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,960
Messages
6,122,479
Members
449,088
Latest member
Melvetica

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