View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Earl Kiosterud Earl Kiosterud is offline
external usenet poster
 
Posts: 611
Default Multiple returned values into a single cell

Jeff,

This formula will do it, but won't handle the comma and space sequence you want between the
cities. You'll get AtlantaChicagoCleveland.

=IF(B2="Yes",B1,"") & IF(C2="Yes",C1,"") & IF(D2="Yes",D1,"") & IF(E2="Yes",E1,"")

To handle the commas and spaces with a formula might send me into therapy. Someone might
find a manageable way. A user-defined function (UDF) will handle it nicely and reliably).
You'd paste this function into a regular module in the VBE of the workbook:

Function CityString(YesNo As Range, Cities As Range) As String
Dim i As Integer
Dim Yeses As Integer ' count of Yeses (Yes's?)
For i = 1 To YesNo.Count
If LCase(YesNo(i).Value) = "yes" Then
Yeses = Yeses + 1
If Yeses 1 Then CityString = CityString & ", " 'need comma and space
CityString = CityString & Cities(i).Value
End If
Next i
End Function

Then put this in A1 (or any cell). It calls the function:

=CityString(B2:E2,B1:E1)

If you want more cities, just make the ranges in the function call bigger. You can have as
many as you want.
=CityString(B2:F2,B1:F1)
It picks up the city names from the cells, so they can be anything. It takes "Yes", "yes",
"YES" etc. It doesn't look for "No" -- it just looks for "Yes".
--
Earl Kiosterud
www.smokeylake.com

Note:
Top-posting is the norm around here.
Some folks prefer bottom-posting.
But if you bottom-post to a reply that's
already top-posted, the thread gets messy.
When in Rome...
-----------------------------------------------------------------------
"Jeff" wrote in message
...
Hi,

I have an Excel spreadsheet, where I am trying to put multiple results, into
a single cell. For example, I have a dropdown selector "Yes" or "No" in a
row that states whether I want a column Market name returned:
a b c d
e
1 Atlanta Chicago Cincinnati
Cleveland
2 Yes Yes No
Yes
3

What I would like to do is this: return results, within a single cell (say,
a1), all markets that say "Yes", like this: "Atlanta,Chicago,Cleveland". I
would want them speparated by a comma...

Thanks for any help, it's driving me crazy. I've tried H and V lookups,
and I can bring back one market name, but getting the multiple names into
one cell is baffling.

Jeff