ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Combining cell entries to one cell with code (https://www.excelbanter.com/excel-programming/398697-combining-cell-entries-one-cell-code.html)

jnf40

Combining cell entries to one cell with code
 
I have 8 cells in a range what I want to do is loop through these cells and
if they have a name in them put them in the same cell seperated with a comma
and a space, such as
if A1:A8 = my range then I want to see if any of these cells have a name in
them and if so I would get
A1 = John
A2 = Bob
A3 = Harry
B1 = John, Bob, Harry and so on
can this be done?

Sam Wilson

Combining cell entries to one cell with code
 
Sub names()

Dim i As Integer
Dim s As String

With Range("a1")
Do Until IsEmpty(.Offset(i, 0))
s = s & .Offset(i, 0).Value & ","
i = i + 1
Loop

End With
s = Left(s, Len(s) - 1)

Range("b1").Value = s

End Sub

"jnf40" wrote:

I have 8 cells in a range what I want to do is loop through these cells and
if they have a name in them put them in the same cell seperated with a comma
and a space, such as
if A1:A8 = my range then I want to see if any of these cells have a name in
them and if so I would get
A1 = John
A2 = Bob
A3 = Harry
B1 = John, Bob, Harry and so on
can this be done?



All times are GMT +1. The time now is 04:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com