View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Ken Johnson
 
Posts: n/a
Default How do I create a list of items in a column?

Hi stepaim,

you could try this macro...

Public Sub List()
Dim iLastRow As Long
Dim I As Long
Dim strList As String
iLastRow = Range("A" & Range("A:A").Rows.Count).End(xlUp).Row
For I = 1 To iLastRow
If Cells(I, 1).Value < "" Then
strList = strList & Cells(I, 1).Value & ", "
End If
Next
If Right(strList, 2) = ", " Then
Let Cells(1, 2).Value = Left(strList, Len(strList) - 2)
Else: Let Cells(1, 2).Value = strList
End If
Cells(1, 2).EntireColumn.AutoFit
End Sub

If any cells in column A between A1 and the bottommost value is a blank
then it is not included in the list that is placed in B1.
If you want blanks included then use...

Public Sub List()
Dim iLastRow As Long
Dim I As Long
Dim strList As String
iLastRow = Range("A" & Range("A:A").Rows.Count).End(xlUp).Row
For I = 1 To iLastRow
strList = strList & Cells(I, 1).Value & ", "
Next
Let Cells(1, 2).Value = Left(strList, Len(strList) - 2)
Cells(1, 2).EntireColumn.AutoFit
End Sub


Ken Johnson