View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Roger Govier[_8_] Roger Govier[_8_] is offline
external usenet poster
 
Posts: 376
Default merging cells and eliminating spaces for empty cells

Hi Jill

I am assuming that column A contains the name of the person, and columns
B to Z contain the 25 potential courses.

This code will create a list in column AA of the sheet

Sub CreateList()
Dim i As Long, j As Long, lr As Long, list As String
Dim ws As Worksheet
Set ws = ActiveSheet
lr = ws.Cells(Rows.Count, "A").End(xlUp).Row

For i = 2 To lr
For j = 2 To 26
If ws.Cells(i, j).Value < "" Then
If list = "" Then
list = ws.Cells(i, j).Value
Else
list = list & " ," & ws.Cells(i, j).Value
End If
End If
Next j
ws.Cells(i, "AA") = list
list = ""
Next i
End Sub

To Install
Copy code
Alt+F11 to invoke VB Editor
Alt+I+M to Insert Module
Paste code into White pane that appears
Alt+F11 to return to Excel

To use
Alt+F8 to bring up macro list
Select macro name
Run


--
Regards
Roger Govier

Jill wrote:
I want to merge the text from about 25 columns into one column. It is a
course list so each registrant has a different combination of courses. Is
there a way to do this and not have a bunch of extra spaces wherever someone
does not have a course?