View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Gary''s Student Gary''s Student is offline
external usenet poster
 
Posts: 11,058
Default Concatenating adjacent cells ignoring blanks and adding a delimite

Try the following User Defined Function:

Function kittenate(r As Range) As String
kittenate = ""
star = "*"
For Each rr In r
If rr.Value = "" Then
Else
If kittenate = "" Then
kittenate = rr.Value
Else
kittenate = kittenate & "*" & rr.Value
End If
End If
Next
End Function

UDFs are very easy to install and use:

1. ALT-F11 brings up the VBE window
2. ALT-I
ALT-M opens a fresh module
3. paste the stuff in and close the VBE window

If you save the workbook, the UDF will be saved with it.

To use the UDF from the normal Excel window, just enter it like a normal
Excel Function, that is =kittenate(A1:Z1)

To remove the UDF:

1. bring up the VBE window as above
2. clear the code out
3. close the VBE window

To learn more about UDFs, see:

http://www.cpearson.com/excel/Writin...ionsInVBA.aspx

--
Gary''s Student - gsnu201001


"Bob Freeman" wrote:

Hello, I am trying to create a formula which concatenates 12 adjacent cells
in a row but excludes any blank cells and puts a delimiting character *
between each instance. Please find a 4 column example below.

ID 1 2 3 4 Result
Z A C D A*C*D
Y B C B*C
X A B D A*B*D

This will be used in a 10,000 row Excel 2007 spreadsheet and each row is
potentially different - there are at least 5 blank cells on each row and
usually more.

Any help is gratefully received. Many thanks, Bob.