Questions about autofill and vlookup()

Sissyfoo

New Member
Joined
Oct 7, 2005
Messages
26
Hi,

2 questions for you today. :)

Is it possible to compare 2 columns when using vlookup or something similar? For example, the spreadsheet I'm dealing with has 2 columns and I need to pull data from another worksheet into a third column.

Column 1 has company names with a lot of duplicates and column 2 has employee names (some duplicate names but not as many). The other worksheet has 3 columns. Columns 1 and 2 are identical to the previous worksheet and column 3 has e-mail addresses.

Is it possible to compare and match the data in column 1 + 2 and, if they match up with columns 1 + 2 in worksheet 2, then pull data contained on the same row but in the third column?

That's the first question!

The second question is this:

How can I write a script that will fill a range of cells with a formula (e.g. vlookup)? I tried to use autofill but it messes up the ranges and increments the lookup_value by 1 (which is what I want) but at the same time increments the table_array values by 1 as well which is not what I want. How can I get around this?

Sorry for all the questions. Hope someone can help me out. :D

James
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Just to answer the second question...

You need to make the lookup range "absolute" by using $ signs,e.g.

=VLOOKUP(A1,$B$2:$D$3,3,0)

when you drag this formula down (or autofill) the lookup value will change but the range won't
 
Upvote 0
Wewhoo! Thanks for the speedy reply. :) Now I just need to get an answer to question 1 and my day *might* start to be less crappy. :)
 
Upvote 0
Perhaps the easiest way is to concatenate the first two columns in worksheet 2 and then use an INDEX/MATCH formula to get the corresponding email addresses,

here's an example. I show everything on one worksheet to keep it simple but it will work exactly the same on 2 separate sheets as long as you use the correct references.
Book1
ABCDEFG
1company 4bloggsjoebloggs@co4.comcompany 4#bloggs
2business 6bakerbilly.baker@businees6.co.ukbusiness 6#baker
3oil companyhoudinibhoudini@oilco.comoil company#houdini
4biscuit makerwhitewhite@biscuitsRus.combiscuit maker#white
5
6
7
8
9
10business 6bakerbilly.baker@businees6.co.uk
11oil companyblack#N/A
12oil companyhoudinibhoudini@oilco.com
13
Sheet4


Formula in E1 copied down

=A1&"#"&B1

Formula in C10 copied down

=INDEX($C$1:$C$4,MATCH(A10&"#"&B10,$E$1:$E$4,0))

note that if you insert the concatenated column to the left of the email addresses then you could use a VLOOKUP but you may not want to alter your worksheet in this way
 
Upvote 0
I hope I'm grasping your intent correctly. Let's start with the Original sheet, with data in Columns A, B, and C.
MainWorkbook.xls
ABCD
1Company NameEmployee NameEmail
2Company AEmployee1Employee1@Company A.com
3Company BEmployee2Employee2@Company B.com
4Company AEmployee1Employee1@Company A.com
5Company CEmployee3Employee3@Company C.com
6Company AEmployee1Employee1@Company A.com
7Company AEmployee3Employee3@Company A.com
8Company CEmployee2Employee2@Company C.com
9Company BEmployee1Employee1@Company B.com
10Company AEmployee3Employee3@Company A.com
11Company BEmployee2Employee2@Company B.com
12Company CEmployee2Employee2@Company C.com
13Company AEmployee3Employee3@Company A.com
14Company CEmployee1Employee1@Company C.com
15Company AEmployee3Employee3@Company A.com
16Company AEmployee1Employee1@Company A.com
17Company BEmployee2Employee2@Company B.com
18Company BEmployee2Employee2@Company B.com
19Company CEmployee3Employee3@Company C.com
20Company BEmployee1Employee1@Company B.com
21Company CEmployee2Employee2@Company C.com
Original


And then the Copy sheet, which has a formula for Column C:
MainWorkbook.xls
ABCD
1Company NameEmployee Name
2Company AEmployee1Employee1@Company A.com
3Company BEmployee1 
4Company AEmployee1Employee1@Company A.com
5Company CEmployee3Employee3@Company C.com
6Company AEmployee1Employee1@Company A.com
7Company AEmployee3Employee3@Company A.com
8Company CEmployee2Employee2@Company C.com
9Company BEmployee1Employee1@Company B.com
10Company AEmployee3Employee3@Company A.com
11Company BEmployee2Employee2@Company B.com
12Company CEmployee2Employee2@Company C.com
13Company AEmployee3Employee3@Company A.com
14Company CEmployee1Employee1@Company C.com
15Company AEmployee3Employee3@Company A.com
16Company AEmployee1Employee1@Company A.com
17Company BEmployee2Employee2@Company B.com
18Company BEmployee2Employee2@Company B.com
19Company CEmployee3Employee3@Company C.com
20Company BEmployee1Employee1@Company B.com
21Company CEmployee2Employee2@Company C.com
Copy


Formula in Column C is:

=IF(AND(A2=Original!A2,B2=Original!B2),Original!C2,"")

Is that what you're after? When I read it the first time, it seemed like you wanted something a little more complicated. Let me know if that's not what you're looking for, and I'll look at it again.
 
Upvote 0
I think that Barry may have cracked it but I will need to test it on my own spreadsheet to make sure. Unfortunately I've just been given even more work which has an even *higher* priority so I'll have to post tomorrow whether or not it worked. Thanks for the quickness of your replies though. Both were really helpful. :)
 
Upvote 0
Barry's solution was perfect! I would never have thought of concatenating the two columns. :) Thanks!!

Thanks also for your help, Tazguy. Appreciate it. :)
 
Upvote 0

Forum statistics

Threads
1,214,991
Messages
6,122,628
Members
449,095
Latest member
bsb1122

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