Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 202
Default How do I lookup several values and concatenate the results?

I have data that comes out of the system of record like this.
Item # Description
1234 Widget
1234 Blue
1234 Large
2345 Thingy
2345 Purple
3456 Gizmo
3456 Red
3456 Large
3456 Square
3456 With Buttons

How do I combine the variable number of descriptions into one field for each
item #? Each item doesn't have the same amount of descriptions.
I want the output to be like this.
Item # Description
1234 "Widget,Blue,Large"
2345 "Thingy,Purple"
3456 "Gizmo,Red,Large,Square,With Buttons"

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default How do I lookup several values and concatenate the results?

You could use a macro.

I'm guessing that you really didn't want the double quotes around the longer
description.

Option Explicit
Sub testme()

Dim wks As Worksheet
Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long

Set wks = Worksheets("Sheet1")

With wks
FirstRow = 2 'headers in row 1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = LastRow To FirstRow + 1 Step -1
If .Cells(iRow - 1, "A").Value = .Cells(iRow, "A").Value Then
'same group
.Cells(iRow - 1, "B").Value _
= .Cells(iRow - 1, "B").Value _
& "," & .Cells(iRow, "B").Value
.Rows(iRow).Delete
End If
Next iRow
End With

End Sub

If you're new to macros:

Debra Dalgleish has some notes how to implement macros he
http://www.contextures.com/xlvba01.html

David McRitchie has an intro to macros:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Ron de Bruin's intro to macros:
http://www.rondebruin.nl/code.htm

(General, Regular and Standard modules all describe the same thing.)

Jane wrote:

I have data that comes out of the system of record like this.
Item # Description
1234 Widget
1234 Blue
1234 Large
2345 Thingy
2345 Purple
3456 Gizmo
3456 Red
3456 Large
3456 Square
3456 With Buttons

How do I combine the variable number of descriptions into one field for each
item #? Each item doesn't have the same amount of descriptions.
I want the output to be like this.
Item # Description
1234 "Widget,Blue,Large"
2345 "Thingy,Purple"
3456 "Gizmo,Red,Large,Square,With Buttons"


--

Dave Peterson
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 you make the results of a concatenate permanent text? Susan Excel Worksheet Functions 3 May 7th 10 09:12 PM
CONCATENATE not producing any results JennieSarah Excel Worksheet Functions 3 February 20th 09 09:42 AM
CONCATENATE not producing any results Pete_UK Excel Worksheet Functions 0 February 19th 09 05:04 PM
Problem with Concatenate - Results are too long for CSV DrewPaik Excel Worksheet Functions 4 June 24th 08 08:49 PM
I can't get my concatenate formula results to show Lauren Excel Discussion (Misc queries) 3 November 18th 05 04:55 PM


All times are GMT +1. The time now is 07:53 AM.

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"