#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 21
Default Multiple lookup

I have a worksheet that list all employees by employer number. I have a
second worksheet whereby I would like to enter the employer number and have
all the employees associated with that employer number listed.

How best can I do this?

Vlookup will only provide one employee. There has got to be a simple way to
do this.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Multiple lookup

AutoFilter is the usual way to list all the rows associated with a match to a
given value on a given column.
--
Gary''s Student - gsnu200780


"JeffH" wrote:

I have a worksheet that list all employees by employer number. I have a
second worksheet whereby I would like to enter the employer number and have
all the employees associated with that employer number listed.

How best can I do this?

Vlookup will only provide one employee. There has got to be a simple way to
do this.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 21
Default Multiple lookup

I realize autofilter is a way to view data in a worksheet. However, I think
my problem is a little different.

On worksheet 1, I want to input the employer number and have it
reference/list from worksheet 2 all the employees listed by employer number.
Vlookup doesn't work because there are multiple employees per employer
number.

I realize I could go to worksheet 2 and simply do an autofilter, but the
report is on worksheet 1.

I appreciate your help.

"Gary''s Student" wrote:

AutoFilter is the usual way to list all the rows associated with a match to a
given value on a given column.
--
Gary''s Student - gsnu200780


"JeffH" wrote:

I have a worksheet that list all employees by employer number. I have a
second worksheet whereby I would like to enter the employer number and have
all the employees associated with that employer number listed.

How best can I do this?

Vlookup will only provide one employee. There has got to be a simple way to
do this.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Multiple lookup

This is just an example that you can adapt to your specific needs. Say that
in Sheet2 the numbers are in column A and and the names are in column B.

In Sheet1 we put the required number in cell A1

In a standard module, put the following VBA code:

Sub xfr()
Dim rxfr As Range
Set s1 = Sheets("Sheet1")
Set s2 = Sheets("Sheet2")
v = s1.Range("A1").Value
n = s2.Cells(Rows.Count, 1).End(xlUp).Row
Application.EnableEvents = False
s1.Range("B:B").Clear
Set rxfr = Nothing
For i = 1 To n
If (s2.Cells(i, 1).Value = v) Then
If rxfr Is Nothing Then
Set rxfr = s2.Cells(i, 2)
Else
Set rxfr = Union(rxfr, s2.Cells(i, 2))
End If
End If
Next
rxfr.Copy s1.Range("B1")
Application.EnableEvents = True
End Sub



In the Sheet1 code area put the following event macro:

Private Sub Worksheet_Change(ByVal Target As Range)
Set r = Range("A1")
If Intersect(Target, r) Is Nothing Then Exit Sub
Call xfr
End Sub

The the Sheet2 code area put the following event macro:

Private Sub Worksheet_Change(ByVal Target As Range)
Set r = Range("A:B")
If Intersect(Target, r) Is Nothing Then Exit Sub
Call xfr
End Sub

Now whenever you change the table in Sheet2 or the lookup value in Sheet1,
the lookup process will refresh.
--
Gary''s Student - gsnu200780


"JeffH" wrote:

I realize autofilter is a way to view data in a worksheet. However, I think
my problem is a little different.

On worksheet 1, I want to input the employer number and have it
reference/list from worksheet 2 all the employees listed by employer number.
Vlookup doesn't work because there are multiple employees per employer
number.

I realize I could go to worksheet 2 and simply do an autofilter, but the
report is on worksheet 1.

I appreciate your help.

"Gary''s Student" wrote:

AutoFilter is the usual way to list all the rows associated with a match to a
given value on a given column.
--
Gary''s Student - gsnu200780


"JeffH" wrote:

I have a worksheet that list all employees by employer number. I have a
second worksheet whereby I would like to enter the employer number and have
all the employees associated with that employer number listed.

How best can I do this?

Vlookup will only provide one employee. There has got to be a simple way to
do this.

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 21
Default Multiple lookup

Thanks Gary, I appreciate your help. I've entered your code but I am getting
an error when it tries to copy.

"rxfr.Copy s1.Range("B1")" gets hung up and I'm not versed in VB code enough
to figure it out.

"Gary''s Student" wrote:

This is just an example that you can adapt to your specific needs. Say that
in Sheet2 the numbers are in column A and and the names are in column B.

In Sheet1 we put the required number in cell A1

In a standard module, put the following VBA code:

Sub xfr()
Dim rxfr As Range
Set s1 = Sheets("Sheet1")
Set s2 = Sheets("Sheet2")
v = s1.Range("A1").Value
n = s2.Cells(Rows.Count, 1).End(xlUp).Row
Application.EnableEvents = False
s1.Range("B:B").Clear
Set rxfr = Nothing
For i = 1 To n
If (s2.Cells(i, 1).Value = v) Then
If rxfr Is Nothing Then
Set rxfr = s2.Cells(i, 2)
Else
Set rxfr = Union(rxfr, s2.Cells(i, 2))
End If
End If
Next
rxfr.Copy s1.Range("B1")
Application.EnableEvents = True
End Sub



In the Sheet1 code area put the following event macro:

Private Sub Worksheet_Change(ByVal Target As Range)
Set r = Range("A1")
If Intersect(Target, r) Is Nothing Then Exit Sub
Call xfr
End Sub

The the Sheet2 code area put the following event macro:

Private Sub Worksheet_Change(ByVal Target As Range)
Set r = Range("A:B")
If Intersect(Target, r) Is Nothing Then Exit Sub
Call xfr
End Sub

Now whenever you change the table in Sheet2 or the lookup value in Sheet1,
the lookup process will refresh.
--
Gary''s Student - gsnu200780


"JeffH" wrote:

I realize autofilter is a way to view data in a worksheet. However, I think
my problem is a little different.

On worksheet 1, I want to input the employer number and have it
reference/list from worksheet 2 all the employees listed by employer number.
Vlookup doesn't work because there are multiple employees per employer
number.

I realize I could go to worksheet 2 and simply do an autofilter, but the
report is on worksheet 1.

I appreciate your help.

"Gary''s Student" wrote:

AutoFilter is the usual way to list all the rows associated with a match to a
given value on a given column.
--
Gary''s Student - gsnu200780


"JeffH" wrote:

I have a worksheet that list all employees by employer number. I have a
second worksheet whereby I would like to enter the employer number and have
all the employees associated with that employer number listed.

How best can I do this?

Vlookup will only provide one employee. There has got to be a simple way to
do this.



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 21
Default Multiple lookup

Gary

Here is the code I have entered.

Note that the range in s1 ("Med UW Work Up") starts at A14, not A1
The data on s2 ("Census") starts at cell A2

Sub xfr()

Dim rxrf As Range
Set s1 = Sheets("Med UW Work Up")
Set s2 = Sheets("Census")
v = s1.Range("a14").Value
n = s2.Cells(Rows.Count, 2).End(xlUp).Row
Application.EnableEvents = False
s1.Range("B14:J66").Clear
Set rxfr = Nothing
For i = 14 To n
If (s2.Cells(i, 1).Value = v) Then
If rxfr Is Nothing Then
Set rxfr = s2.Cells(i, 2)
Else
Set rxfr = Union(rxfr, s2.Cells(i, 2))
End If
End If
Next
rxfr.Copy s1.Range("B1") I would think this should be "B14" because that is
where the range starts. However it errored out even when at "B14".

End Sub


"Gary''s Student" wrote:

This is just an example that you can adapt to your specific needs. Say that
in Sheet2 the numbers are in column A and and the names are in column B.

In Sheet1 we put the required number in cell A1

In a standard module, put the following VBA code:

Sub xfr()
Dim rxfr As Range
Set s1 = Sheets("Sheet1")
Set s2 = Sheets("Sheet2")
v = s1.Range("A1").Value
n = s2.Cells(Rows.Count, 1).End(xlUp).Row
Application.EnableEvents = False
s1.Range("B:B").Clear
Set rxfr = Nothing
For i = 1 To n
If (s2.Cells(i, 1).Value = v) Then
If rxfr Is Nothing Then
Set rxfr = s2.Cells(i, 2)
Else
Set rxfr = Union(rxfr, s2.Cells(i, 2))
End If
End If
Next
rxfr.Copy s1.Range("B1")
Application.EnableEvents = True
End Sub



In the Sheet1 code area put the following event macro:

Private Sub Worksheet_Change(ByVal Target As Range)
Set r = Range("A1")
If Intersect(Target, r) Is Nothing Then Exit Sub
Call xfr
End Sub

The the Sheet2 code area put the following event macro:

Private Sub Worksheet_Change(ByVal Target As Range)
Set r = Range("A:B")
If Intersect(Target, r) Is Nothing Then Exit Sub
Call xfr
End Sub

Now whenever you change the table in Sheet2 or the lookup value in Sheet1,
the lookup process will refresh.
--
Gary''s Student - gsnu200780


"JeffH" wrote:

I realize autofilter is a way to view data in a worksheet. However, I think
my problem is a little different.

On worksheet 1, I want to input the employer number and have it
reference/list from worksheet 2 all the employees listed by employer number.
Vlookup doesn't work because there are multiple employees per employer
number.

I realize I could go to worksheet 2 and simply do an autofilter, but the
report is on worksheet 1.

I appreciate your help.

"Gary''s Student" wrote:

AutoFilter is the usual way to list all the rows associated with a match to a
given value on a given column.
--
Gary''s Student - gsnu200780


"JeffH" wrote:

I have a worksheet that list all employees by employer number. I have a
second worksheet whereby I would like to enter the employer number and have
all the employees associated with that employer number listed.

How best can I do this?

Vlookup will only provide one employee. There has got to be a simple way to
do this.

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Multiple lookup

Thanks for your patience. I will renew the attack tomorrow when I get to a
computer with Excel.
--
Gary''s Student - gsnu200780


"JeffH" wrote:

Gary

Here is the code I have entered.

Note that the range in s1 ("Med UW Work Up") starts at A14, not A1
The data on s2 ("Census") starts at cell A2

Sub xfr()

Dim rxrf As Range
Set s1 = Sheets("Med UW Work Up")
Set s2 = Sheets("Census")
v = s1.Range("a14").Value
n = s2.Cells(Rows.Count, 2).End(xlUp).Row
Application.EnableEvents = False
s1.Range("B14:J66").Clear
Set rxfr = Nothing
For i = 14 To n
If (s2.Cells(i, 1).Value = v) Then
If rxfr Is Nothing Then
Set rxfr = s2.Cells(i, 2)
Else
Set rxfr = Union(rxfr, s2.Cells(i, 2))
End If
End If
Next
rxfr.Copy s1.Range("B1") I would think this should be "B14" because that is
where the range starts. However it errored out even when at "B14".

End Sub


"Gary''s Student" wrote:

This is just an example that you can adapt to your specific needs. Say that
in Sheet2 the numbers are in column A and and the names are in column B.

In Sheet1 we put the required number in cell A1

In a standard module, put the following VBA code:

Sub xfr()
Dim rxfr As Range
Set s1 = Sheets("Sheet1")
Set s2 = Sheets("Sheet2")
v = s1.Range("A1").Value
n = s2.Cells(Rows.Count, 1).End(xlUp).Row
Application.EnableEvents = False
s1.Range("B:B").Clear
Set rxfr = Nothing
For i = 1 To n
If (s2.Cells(i, 1).Value = v) Then
If rxfr Is Nothing Then
Set rxfr = s2.Cells(i, 2)
Else
Set rxfr = Union(rxfr, s2.Cells(i, 2))
End If
End If
Next
rxfr.Copy s1.Range("B1")
Application.EnableEvents = True
End Sub



In the Sheet1 code area put the following event macro:

Private Sub Worksheet_Change(ByVal Target As Range)
Set r = Range("A1")
If Intersect(Target, r) Is Nothing Then Exit Sub
Call xfr
End Sub

The the Sheet2 code area put the following event macro:

Private Sub Worksheet_Change(ByVal Target As Range)
Set r = Range("A:B")
If Intersect(Target, r) Is Nothing Then Exit Sub
Call xfr
End Sub

Now whenever you change the table in Sheet2 or the lookup value in Sheet1,
the lookup process will refresh.
--
Gary''s Student - gsnu200780


"JeffH" wrote:

I realize autofilter is a way to view data in a worksheet. However, I think
my problem is a little different.

On worksheet 1, I want to input the employer number and have it
reference/list from worksheet 2 all the employees listed by employer number.
Vlookup doesn't work because there are multiple employees per employer
number.

I realize I could go to worksheet 2 and simply do an autofilter, but the
report is on worksheet 1.

I appreciate your help.

"Gary''s Student" wrote:

AutoFilter is the usual way to list all the rows associated with a match to a
given value on a given column.
--
Gary''s Student - gsnu200780


"JeffH" wrote:

I have a worksheet that list all employees by employer number. I have a
second worksheet whereby I would like to enter the employer number and have
all the employees associated with that employer number listed.

How best can I do this?

Vlookup will only provide one employee. There has got to be a simple way to
do this.

  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Multiple lookup

How do you want to display those employees? In one cell, but separated by
commas? In separate cells???

If you want a single cell:

http://groups.google.co.uk/group/mic...28f1ba868980a8

or

http://snipurl.com/24yfb (first post in the thread)




If you wanted separate cells (horizontal or veritical), take a look he

http://groups.google.co.uk/group/mic...467b485b0a4f4d

or

http://snipurl.com/24yf3

JeffH wrote:

I have a worksheet that list all employees by employer number. I have a
second worksheet whereby I would like to enter the employer number and have
all the employees associated with that employer number listed.

How best can I do this?

Vlookup will only provide one employee. There has got to be a simple way to
do this.


--

Dave Peterson
  #9   Report Post  
Posted to microsoft.public.excel.misc
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Multiple lookup

Think this little formulas play could also deliver what you want ..

Assume source Employer numbers & Employees in Sheet1,
cols A & B, data from row2 down

In Sheet2,
Assume A1 will be where you input the Employer #, eg: 111
Put in B1: =IF($A$1="","",IF(Sheet2!A2=$A$1,ROWS($1:1),""))
Put in C1: =IF(ROW()COUNT(B:B),"",INDEX(Sheet2!B:B,SMALL(B:B ,ROW())+1))
Select B1:C1, copy down to cover the max expected extent of data in Sheet1,
eg down to say C300. Minimize/hide away col B. Col C will return all the
employees for the employer # input in A1, neatly bunched at the top.
--
Max
Singapore
http://savefile.com/projects/236895
xdemechanik
---
"JeffH" wrote:
On worksheet 1, I want to input the employer number and have it
reference/list from worksheet 2 all the employees listed by employer number.
Vlookup doesn't work because there are multiple employees per employer
number.

I realize I could go to worksheet 2 and simply do an autofilter, but the
report is on worksheet 1.


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
Multiple lookup values and adding multiple rates across together ssolomon Excel Worksheet Functions 5 November 16th 07 09:02 PM
Lookup using multiple sheets and multiple criteria, sorry if 2 pos kjguillermo Excel Worksheet Functions 4 January 16th 07 03:21 AM
Lookup using multiple sheets and multiple criteria kjguillermo Excel Discussion (Misc queries) 2 January 14th 07 10:28 AM
Lookup in Multiple Columns, Return Multiple Values andy62 Excel Worksheet Functions 3 July 6th 06 02:36 AM
multiple Lookup shaj Excel Worksheet Functions 2 November 17th 05 07:10 PM


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