Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 52
Default merging cells and eliminating spaces for empty cells

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?


  #2   Report Post  
Posted to microsoft.public.excel.misc
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?


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default merging cells and eliminating spaces for empty cells

You could use a User Defined Function and enter a formula.

Function ConCatRange(CellBlock As Range, Optional Delim As String = "") _
As String
'entered as =concatrange(a1:a10,"|") desired delimiter between quotes
Dim Cell As Range
Dim sbuf As String

For Each Cell In CellBlock.Cells
If Cell.text < "" Then
sbuf = sbuf & Cell.text & Delim
End If
Next Cell

ConCatRange22 = Left(sbuf, Len(sbuf) - Len(Delim))
End Function

This goes into a General Module.

See Roger's post for how-tos.


Gord Dibben MS Excel MVP

On Fri, 2 Apr 2010 10:31:01 -0700, 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?


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Eliminating Spaces JB Excel Discussion (Misc queries) 5 May 31st 07 05:22 PM
eliminating extra spaces in Excel cells Laura1 Excel Discussion (Misc queries) 4 March 17th 06 05:34 PM
eliminating empty cells from chart area financeman500 Charts and Charting in Excel 1 February 22nd 06 04:41 PM
Sumproduct ... Empty Cells vs Spaces? Ken Excel Discussion (Misc queries) 9 December 17th 04 08:03 PM
Empty Cells, Spaces, Cond Format? Ken Excel Discussion (Misc queries) 3 December 4th 04 04:47 PM


All times are GMT +1. The time now is 08:32 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"