Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Concatenate contiguous fields on one worksheet into 1 field on ano

I have an Excel workbook that has 2 worksheets. One worksheet (called Master)
has company and address information in separate, contiguous cells. I need to
concatenate those cells into a single cell on the other worksheet, with line
breaks between.

Example:
Company Name
Address Line 1
Address Line 2
City, ST Zipcode

Some addresses will not have the Address Line 2, and I don't want to show a
blank line.

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Concatenate contiguous fields on one worksheet into 1 field on ano

Function ConCatRange(CellBlock As Range) As String
'ignores blank cells
'for non-contiguous cells =ccr((a1:a10,c4,c6,e1:e5))
Dim Cell As Range
Dim sbuf As String
For Each Cell In CellBlock
If Len(Cell.Text) 0 Then sbuf = sbuf & Cell.Text & vbLf
Next
ConCatRange = Left(sbuf, Len(sbuf) - 1)
End Function

=concatrange(Master!A1:A4)


Gord Dibben MS Excel MVP

On Mon, 5 Oct 2009 14:30:01 -0700, MargeB
wrote:

I have an Excel workbook that has 2 worksheets. One worksheet (called Master)
has company and address information in separate, contiguous cells. I need to
concatenate those cells into a single cell on the other worksheet, with line
breaks between.

Example:
Company Name
Address Line 1
Address Line 2
City, ST Zipcode

Some addresses will not have the Address Line 2, and I don't want to show a
blank line.

Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Concatenate contiguous fields on one worksheet into 1 field on

Thanks for the reply. I haven't had a chance to try it yet.

"Gord Dibben" wrote:

Function ConCatRange(CellBlock As Range) As String
'ignores blank cells
'for non-contiguous cells =ccr((a1:a10,c4,c6,e1:e5))
Dim Cell As Range
Dim sbuf As String
For Each Cell In CellBlock
If Len(Cell.Text) 0 Then sbuf = sbuf & Cell.Text & vbLf
Next
ConCatRange = Left(sbuf, Len(sbuf) - 1)
End Function

=concatrange(Master!A1:A4)


Gord Dibben MS Excel MVP

On Mon, 5 Oct 2009 14:30:01 -0700, MargeB
wrote:

I have an Excel workbook that has 2 worksheets. One worksheet (called Master)
has company and address information in separate, contiguous cells. I need to
concatenate those cells into a single cell on the other worksheet, with line
breaks between.

Example:
Company Name
Address Line 1
Address Line 2
City, ST Zipcode

Some addresses will not have the Address Line 2, and I don't want to show a
blank line.

Thanks



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
How do I concatenate two date fields fetter Excel Discussion (Misc queries) 2 May 4th 10 05:57 PM
Format date and time from one contiguous field RCCruiser Excel Discussion (Misc queries) 4 August 19th 08 07:08 PM
copy field settings of a field to other fields in same pivot tbl new22007 Excel Worksheet Functions 0 May 8th 08 10:22 PM
clear contiguous fields with one keystroke Marshall Excel Programming 1 November 15th 07 10:40 PM
How to Join/concatenate a date field with a time field in Excel? Alan Excel Discussion (Misc queries) 4 August 9th 05 10:07 PM


All times are GMT +1. The time now is 10:34 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"