LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 367
Default advanced lookup feature

Hey SaH

I wrote you a small sub:
Enter them in a module in your worksheet, change ws_source and
ws_targets name and run "find_comp"
(the function find_range is a courtesy from OZGrid)

'---------------------------------------------------------------------------------
Sub findComp()

Dim ws_source As Worksheet
Dim ws_target As Worksheet

Set ws_source = Worksheets("sheet1")
Set ws_target = Worksheets("sheet2")

ws_target.Range("B1:IV65536").Delete

Dim coll_ As Collection

For i = 1 To ws_target.Cells(65536, 1).End(xlUp).Row
Set coll_ = Return_Items(ws_target.Cells(i, 1), ws_source)

count_ = 2

For Each itm In coll_
ws_target.Cells(i, count_) = itm
count_ = count_ + 1
Next itm

Next i

End Sub

Function Return_Items(Item As String, WS As Worksheet) As Collection

On Error Resume Next

Dim rng As Range
Dim cell_ As Range
Dim temp As New Collection

Set rng = Find_Range(Item, WS.Range("B1:F" & WS.Cells(65536,
1).End(xlUp).Row))

For Each cell_ In rng
temp.Add WS.Cells(cell_.Row, 1), CStr(WS.Cells(cell_.Row, 1))
Next cell_

Set Return_Items = temp

End Function

Function Find_Range(Find_Item As Variant, _
Search_Range As Range, _
Optional LookIn As Variant, _
Optional LookAt As Variant, _
Optional MatchCase As Boolean) As Range

Dim c As Range
If IsMissing(LookIn) Then LookIn = xlValues 'xlFormulas
If IsMissing(LookAt) Then LookAt = xlWhole 'xlPart
If IsMissing(MatchCase) Then MatchCase = False

With Search_Range
Set c = .Find( _
What:=Find_Item, _
LookIn:=LookIn, _
LookAt:=LookAt, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=MatchCase, _
SearchFormat:=False)
If Not c Is Nothing Then
Set Find_Range = c
firstAddress = c.Address
Do
Set Find_Range = Union(Find_Range, c)
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With

End Function
'---------------------------------------------------------------------------------

Pay attention, there might be a wordwrap!!!

hth

Carlo


On Jan 8, 10:31*am, Southern at Heart
wrote:
This may be impossible, but here's what needs to be done.
Sheet1 has a list of parts in column A, & colums B thru F lists components
that make up that part.
Sheet2 column A is a list of components, and I want Column B to list all the
parts (from sheet1!columnA) that use that component. *
So in laymens terms, Sheet2B needs to search sheet1B-F and find ALL the
instances of sheet2A. *So it may find several parts from sheet 1 that all use
that component, and I need them to be listed in sheet2 next to the component
number
thanks for any help!


 
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 use the LOOKUP feature in Excel Elena D Excel Worksheet Functions 2 January 20th 08 06:18 PM
Excel Advanced Search (Feature/Option/Plug-in) Safal Excel Discussion (Misc queries) 2 December 8th 06 03:49 PM
How do Icorrectly use the LookUp feature when the cells contain wo Lee Hawken Excel Discussion (Misc queries) 1 September 9th 06 07:16 AM
Advanced Lookup (lookup for 2 values) 0-0 Wai Wai ^-^ Excel Worksheet Functions 2 March 30th 06 07:09 PM
Help on Lookup feature JLH Excel Discussion (Misc queries) 2 December 28th 05 08:01 PM


All times are GMT +1. The time now is 10:14 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"