Combining cell entries to one cell with code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top