J
Josh Rogers
I'm attempting to display in a cell a concatenated list of items that
match in an array. Here is an example:
Data:
A B
1 Bob Chicken
2 Sally Steak
3 Bob Salad
4 Susan Salad
5 Bob Soda
And for the lookup:
A B
1 Bob Chicken Salad Soda
2 Sally Steak
3 Susan Salad
Column B of the lookup is the portion I'm focusing on here.
Originally, i was able to successfully do this using MCONCAT from the
morefunc addon. This worked great, except I am sending this
spreadsheet to others that do not have this addon installed, and it
isn't reasonable to ask them to install it, so I attempted to change
it to the aconcat UDF from Harlan Grove:
Function ACONCAT(a As Variant, Optional sep As String = "") As String
' Harlan Grove, Mar 2002
Dim y As Variant
If TypeOf a Is Range Then
For Each y In a.Cells
ACONCAT = ACONCAT & y.Value & sep
Next y
ElseIf IsArray(a) Then
For Each y In a
ACONCAT = ACONCAT & y & sep
Next y
Else
ACONCAT = ACONCAT & a & sep
End If
ACONCAT = Left(ACONCAT, Len(ACONCAT) - Len(sep))
End Function
This results in a #NAME error. I can't seem to figure out why. I've
grabbed screenshots of the error:
Before Eval: http://imagebin.ca/view/L0mxlr8.html
Step 1 of Eval: http://imagebin.ca/view/ev1f3A1.html
I placed this in 'Module1' at first, then tried placing it in a sheet
module. I'm not sure what else to check. This is my first attempt at
a UDF, so I appreciate any insight. I'm using Excel 2007 (as are many
of the folks that will be viewing the document), but am saving in
Excel 2003 for compatibility.
match in an array. Here is an example:
Data:
A B
1 Bob Chicken
2 Sally Steak
3 Bob Salad
4 Susan Salad
5 Bob Soda
And for the lookup:
A B
1 Bob Chicken Salad Soda
2 Sally Steak
3 Susan Salad
Column B of the lookup is the portion I'm focusing on here.
Originally, i was able to successfully do this using MCONCAT from the
morefunc addon. This worked great, except I am sending this
spreadsheet to others that do not have this addon installed, and it
isn't reasonable to ask them to install it, so I attempted to change
it to the aconcat UDF from Harlan Grove:
Function ACONCAT(a As Variant, Optional sep As String = "") As String
' Harlan Grove, Mar 2002
Dim y As Variant
If TypeOf a Is Range Then
For Each y In a.Cells
ACONCAT = ACONCAT & y.Value & sep
Next y
ElseIf IsArray(a) Then
For Each y In a
ACONCAT = ACONCAT & y & sep
Next y
Else
ACONCAT = ACONCAT & a & sep
End If
ACONCAT = Left(ACONCAT, Len(ACONCAT) - Len(sep))
End Function
This results in a #NAME error. I can't seem to figure out why. I've
grabbed screenshots of the error:
Before Eval: http://imagebin.ca/view/L0mxlr8.html
Step 1 of Eval: http://imagebin.ca/view/ev1f3A1.html
I placed this in 'Module1' at first, then tried placing it in a sheet
module. I'm not sure what else to check. This is my first attempt at
a UDF, so I appreciate any insight. I'm using Excel 2007 (as are many
of the folks that will be viewing the document), but am saving in
Excel 2003 for compatibility.