Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
DG DG is offline
external usenet poster
 
Posts: 46
Default vlookup is not the answer

I have a list of parts that are in Kits (like a socket set). It is two
columns A = PARTS and B = KIT. It is sorted by Parts. one part can be in
more than one kit and that is what I need to know.

example:

PART KIT
Part_A Kit_1
Part_A Kit_2
Part_A Kit_3
Part_B Kit_2
Part_B Kit_3
Part_C Kit_1

The above array is in a named range called KIT_DATA. And I was going to use
vlookup untill I realized it would only give me the first kit. The above
data is in Sheet2. Sheet1 lists all of the Parts. The objective is to
insert a comment into the Part on sheet1 and put all the Kits that the part
is in (from sheet2 or KIT_DATA) into the comment.

Soooo....

Sheet1

Part_A would have a comment "Kit_1, Kit_2, Kit_3"
Part_B would have a comment "Kit_2, Kit_3"
Part_C would have a comment "Kit_1"

Does that make sense? Can anyone help? I could loop through the whole mess
but it's about 50,000 lines.

DG


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default vlookup is not the answer

See if this will do what you want.

Sub getKit()
Dim lr1 As Long, lr2 As Long
Dim sh1 As Worksheet, sh2 As Worksheet
Dim rng1 As Range, rng2 As Range
Set sh1 = Sheets("Sheet1")
Set sh2 = Sheets("Sheet2")
lr1 = sh1.Cells(Rows.Count, 1).End(xlUp).Row
lr2 = sh2.Cells(Rows.Count, 1).End(xlUp).Row
Set rng1 = sh1.Range("A2:A" & lr1)
Set rng2 = sh2.Range("A2:A" & lr2)
For Each c In rng1
For Each i In rng2
If c.Value = i.Value Then
kt = kt & i.Offset(, 1).Value & vbCrLf
End If
Next
With c.AddComment
.Visible = False
.Text kt
End With
kt = ""
Next
End Sub




"DG" wrote in message
...
I have a list of parts that are in Kits (like a socket set). It is two
columns A = PARTS and B = KIT. It is sorted by Parts. one part can be in
more than one kit and that is what I need to know.

example:

PART KIT
Part_A Kit_1
Part_A Kit_2
Part_A Kit_3
Part_B Kit_2
Part_B Kit_3
Part_C Kit_1

The above array is in a named range called KIT_DATA. And I was going to
use vlookup untill I realized it would only give me the first kit. The
above data is in Sheet2. Sheet1 lists all of the Parts. The objective is
to insert a comment into the Part on sheet1 and put all the Kits that the
part is in (from sheet2 or KIT_DATA) into the comment.

Soooo....

Sheet1

Part_A would have a comment "Kit_1, Kit_2, Kit_3"
Part_B would have a comment "Kit_2, Kit_3"
Part_C would have a comment "Kit_1"

Does that make sense? Can anyone help? I could loop through the whole
mess but it's about 50,000 lines.

DG



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
Vlookup? Questions about answer I got??? Help, please. Dave Excel Discussion (Misc queries) 2 December 4th 08 08:01 PM
vlookup returns wrong answer (off by one row) BAA Excel Worksheet Functions 2 October 4th 08 04:45 AM
VLOOKUP not returning correct answer Alan Davies Excel Worksheet Functions 3 May 10th 06 03:37 PM
vlookup answer in different cell Psychlogic Excel Worksheet Functions 1 January 24th 06 09:40 PM
vlookup search for more then one answer Gemse Excel Discussion (Misc queries) 2 July 4th 05 01:24 PM


All times are GMT +1. The time now is 04:28 PM.

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"