Group

R

Ranjith Kurian

I have Name column with corresponding single alphabets in a different column
for each rows
exmaple:

Name
MON Q D C B N
TUE T
WED H U I T R E J L
THU A S L K V X Z W Q I L


I could like to have macro code to combine each column data to a single cell
as shown below, the Column ‘A’(Name) will always have a name but the other
columns are not fixed (it can increase or decrease)

Example:
Name
MON Q,D,C,B,N
TUE T
WED H,U,I,T,RE,J,L
THU A,S,L,K,V,X,Z,W,Q,I,L
 
S

Sam Wilson

This assumes MON is in A1 - change if necessary:

Sub test()

Dim i As Integer, j As Integer
Dim s As String

With Range("A1")
Do Until IsEmpty(.Offset(i, 0))
Do While Not IsEmpty(.Offset(i, j + 1))
s = s & .Offset(i, j + 1).Value & ","
.Offset(i, j + 1).ClearContents
j = j + 1
Loop
If Not s = "" Then .Offset(i, 1).Value = Left(s, Len(s) - 1)
s = ""
j = 0
i = i + 1
Loop

End With

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

Top