Extracting two values out of a table based on the same index number

dkjonesau

New Member
Joined
May 9, 2014
Messages
46
Hi all,

I'm trying to cross reference initials into a roster. The organisation uses the same roster line number for a pair of employees on the same shift.

An example table is below.

ABCDEFGH
11234SMITH BILLMGROWLS183/ROADBILL SMITHBS
25678JONES FRED2ICOWL/AD183/OPSFRED JONESFJ
39123HOLLY JANEALSOWLS883/OPSJANE HOLLYJH
44567BELL SARAHALSOWL/AD883/OPSSARAH BELLSB
58910HOUSE INDIAICPOWLS1583/OPSINDIA HOUSEIH
62345TOWN VERONICAALSOWLS/AD1583/OPSVERONICA TOWNVT
76789TWIST BARRYALSOWLS2283/OPSBARRY TWISTBT
81235READ ALLISTAIRICPOWLS2283/OPSALLISTAIR READAR

I'm looking for a formula to take the initals for both employees from column H to another pair of cells based on the roster line in column E.

The result would end up looking like this:
123
ALine #Date
BEmp 1Emp 2
C1BSFJ
D8JHSB
E15IHVT
F22BTAR

Both employees found in E1 & E2 (BS & FJ) initials end up in adjacent cells at B2 & B3 against roster line 1 in an alternative summary sheet.

I can't use VLOOKUP as the index for both employees is the same. ie. 1 for line 1, 8 for line 8 etc.

It just returns BS in both Emp 1 & Emp 2.

What is the best formula top put in C2 & C3 in the bottom table to fetch the initials from the pair working line 1 in the top table (ie initials from H1 & H2)

The data coming in is from an external source and is being used for thousands of employees. It can't be customised to make the job easier.

Thanks

Dave
 
Ok, you have got me thinking now about the stragglers here is an idea which may work for all scenarios
if you are able on your data feed sheet is create a helper column in column I as follows
=E2&”_”&COUNTIF($E$2:E2,E2). My double quotes are iPad ones and not windows ones so change accordingly
this will create a value of shift_n where n is 1 or 2 And these can be anywhere on your list

next change you MATCH to look for A2&”_”&”1” and likewise same but with 2 at the end again change the double quotes so you are looking for instance 22_1 and 22_2 as in your last example

this will find the pairs from anywhere in the list

this is one option rather than using array formulas to return Nth matching strings
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Ok, you have got me thinking now about the stragglers here is an idea which may work for all scenarios
if you are able on your data feed sheet is create a helper column in column I as follows
=E2&”_”&COUNTIF($E$2:E2,E2). My double quotes are iPad ones and not windows ones so change accordingly
this will create a value of shift_n where n is 1 or 2 And these can be anywhere on your list

next change you MATCH to look for A2&”_”&”1” and likewise same but with 2 at the end again change the double quotes so you are looking for instance 22_1 and 22_2 as in your last example

this will find the pairs from anywhere in the list

this is one option rather than using array formulas to return Nth matching strings

Hi Jim,

Probably easiest if I deidentify the spreadsheet & include here.

You can see the team member at F19 - the second instance of 22 - is on LSL (leave) in column H. The team member at F27 - third instance of 22 - will cover that line as they duplicate it.

Its an unusual circumstance. Normally the first instances of 22 in the top bracket from 1 - 36 would be in the body of the roster.

I can use a helper column or two if needs be. The text in red is helper columns reversing surname first name to first name surname in column I, then using a GetFirstLetter function to make initials. (Didn't like the names with "prefix surname first name" so the SLL should be LLS but I'll live.)

In this instance i could probably establish a way of determining that the 22 on leave in the body of the roster needs to be swapped with Line 27 by searching the top cells for leave types in col H, but it's messy.

Dave

Capture.PNG
 
Upvote 0
It should be ok to factor in the leave criteria when building the helper column. I should be able to get to my pc in the next hour or so and see what I can come up with
 
Upvote 0
Ok finally on my computer, there are probably slicker ways of doing this but I prefer the easy step by step as its easier to understand and hopefully explains my thinking and or techniques

Book1.xlsx
ABCDEFGHIJK
1ABCDEFGHHelper Able to workHelper OnShift_EmployeeCount
21234SMITH BILLMGROWLS183/ROADA/LBILL SMITHBS11_1
35678JONES FRED2ICOWL/AD183/OPSRDOFRED JONESFJ11_2
49123HOLLY JANEALSOWLS883/OPSRDOJANE HOLLYJH88_1
54567BELL SARAHALSOWL/AD883/OPSRDOSARAH BELLSB88_2
68910HOUSE INDIAICPOWLS1583/OPS3/LCKINDIA HOUSEIH1515_1
72345TOWN VERONICAALSOWLS/AD1583/OPS3/LCKVERONICA TOWNVT1515_2
86789TWIST BARRYALSOWLS2283/OPSLSLHBARRY TWISTBTon leave 
91235READ ALLISTAIRICPOWLS2283/OPS700ALLISTAIR READAR2222_1
101236TIME JUSTINICPOWLS2283/OPSCOSQJUSTIN TIMEJT2222_2
Sheet1
Cell Formulas
RangeFormula
J2:J10J2=IF(LEFT(G2,3)<>"LSL",E2,"on leave")
K2:K10K2=IF(J2 <> "on leave",J2&"_"&COUNTIF($J$2:J2,J2),"")


I have created 2 help columns the first one looks for the string LSL (substitute in what you need) in column G if it finds it sets the helper column value to on_leave, else it copies across the shift number
so in cell J2 enter the following
=IF(LEFT(G2,3)<>"LSL",F2,"on leave")

In column K is our second helper column where we set the ShiftNumber_EmployeeCount to use later on for sheet2
in cell K2 enter the following
=IF(J2 <> "on leave",J2&"_"&COUNTIF($J$2:J2,J2),"")

Now for sheet 2

Book1.xlsx
ABCD
1ABC
21Line #Date
32Emp 1Emp 2
431BSFJ
548JHSB
6515IHVT
7622ARJT
Sheet2
Cell Formulas
RangeFormula
C4:C7C4=INDEX(Sheet1!$I$2:$I$10,MATCH(B4&"_1",Sheet1!$K$2:$K$10,0))
D4:D7D4=INDEX(Sheet1!$I$2:$I$10,MATCH(B4&"_2",Sheet1!$K$2:$K$10,0))


for our INDEX MATCH combination
=INDEX(sheet1!$I$2:$I$10,MATCH(B4&"_1",sheet1!$K$2:$K$10,0))
=INDEX(sheet1!$I$2:$I$10,MATCH(B4&"_2",sheet1!$K$2:$K$10,0))
 
Last edited:
Upvote 0
[
Hey thanks Jim

I’ll have a play with that over the next few days. Let you know how I go. On days off now so will probably be home isolating with the welder in the shed rather than on the computer. Much appreciated!!

Dave
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,334
Members
449,077
Latest member
Jocksteriom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top