Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 410
Default Concatenate the lookup values from all occurences

On Jun 17, 5:37*pm, JLGWhiz wrote:
I didn't address the concatenate part. *But you would have to do some
manipulation to do the concatenate since your loop is only looking at one
item at a time. *You will need a method to mark each item as it is found and
before starting the next loop, do your concatenate. *If you cannot figure it
out, post back.



"jlclyde" wrote:
I am trying very hard to get Excel to look up multiple occuring values
in column A and return the concatenation of all values in B. *For
instance if I have A1 = 1, A2 = 2 and A3 = 1 *and I ahve B1 = cat, B2
= Dog and B3 = goat. * Based on the value in C1 = 1 it woudl return
cat, goat. *Is this possible. *I am trying to do a for next loop, but
I do not know how to offset it to get the values that I want from
column B.


thanks,
Jay- Hide quoted text -


- Show quoted text -


This is the code that I got to work but then I started thinking that
this woudl make more sense as a Function. I have include the finction
below with the problem that I am having.

Sub POs()
Dim MyRange As Range
Set MyRange = Range("A1:A20")
Dim c As Range
For Each c In MyRange
If c = Range("D1").Value Then
Dim Concat As String
Concat = c.Offset(0, 1) & ", "
Dim D7 As String
D7 = Range("D7").Value
Range("D7") = D7 & Concat
End If
Next
End Sub

Function Concpos(Item As Range, Items As Range)

Dim c As Range
For Each c In Items
If c = Range("D1").Value Then
Dim Concat As String
Concat = c.Offset(0, 1).Value & ", "

End If
Concpos = Concat & Concat
Next
End Function

I am unsure how to keep a variable and then add to it. In the Sub it
was easy to use a cell to store the data, but how is it done in a
function?

Thanks,
Jay
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 410
Default Concatenate the lookup values from all occurences

Nevermind. I was over thinking it. below works.

Function Concpos(Item As Range, Items As Range)

Dim c As Range
For Each c In Items

If c = Item Then
Dim Concat As String
Concat = c.Offset(0, 1).Value & ", "
Concpos = Concpos & Concat
End If

Next
End Function

Thanks Jay
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 lookup several values and concatenate the results? Jane Excel Discussion (Misc queries) 1 May 29th 10 02:43 AM
lookup then concatenate Betty Excel Worksheet Functions 1 April 6th 09 05:15 AM
lookup and concatenate Greg Excel Worksheet Functions 4 November 25th 08 02:56 PM
Lookup a value and count the number of associated occurences reddy Excel Discussion (Misc queries) 3 August 27th 08 11:37 PM
vlookup and concatenate multiple occurences jlclyde Excel Discussion (Misc queries) 0 June 17th 08 06:55 PM


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

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

About Us

"It's about Microsoft Excel"