Index a global array by value

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,525
Office Version
  1. 365
Platform
  1. Windows
In Sheet1, I have a table like this but with many more rows.
C/RCDE
6ProductPriceWeight
7M28$29.950.35
8M29$19.950.22
9M44$49.953.50
10S9$9.951.25
11S10$10.951.50

<tbody>
</tbody>

Columns C, D, & E are assigned the global names "Product", "Price", & "Weight" respectively.

In another sheet in the same workbook, I want to create a table like this:
C/RHIJK
6ProductQuanPriceCost
7M445$49.95$249.75
8S1010$10.95$109.50
9M2825$29.95$748.75

<tbody>
</tbody>

where the values in column J are taken from the table in Sheet1.

Is there any way to do that?

Related question, is there a way to do this if Sheet1 is in a different workbook that is not currently open?
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Sheet1

Row\Col
C​
D​
E​
6​
Product
Price
Weight
7​
M28
$29.95
0.35
8​
M29
$19.95
0.22
9​
M44
$49.95
3.5
10​
S9
$9.95
1.25
11​
S10
$10.95
1.5

Name A6:E11 (thus headers included) PTable via the Name Box or FORMULAS | Name Manager.

Save the workbook as jm.xlsx (for example)...

1.

Sheet2

Row\Col
H​
I​
J​
K​
6​
Product
Quan
Price
Cost
7​
M44
5
$49.95
$249.75
8​
S10
10
$10.95
$109.50
9​
M28
25
$29.95
$748.75

In J7 enter and copy down:

=VLOOKUP($H7,PTable,MATCH(J$6,INDEX(PTable,1,0),0),0)

In K7 enter and copy down:

=I7*J7

2. Open a new workbook.

Sheet1 of the new workbook:

Row\Col
A​
B​
C​
D​
1​
Product
Quan
Price
Cost
2​
M44
5
$49.95
$249.75
3​
S10
10
$10.95
$109.50
4​
M28
25
$29.95
$748.75

In C2 enter and copy down:

=VLOOKUP($A2,jm.xlsx!PTable,MATCH(C$1,INDEX(jm.xlsx!PTable,1,0),0),0)

In D2 enter and copy down:

=B2*C2
 
Upvote 0
Sheet1

Row\Col
C​
D​
E​
6​
Product
Price
Weight
7​
M28
$29.95
0.35
8
M29
$19.95
0.22
9
M44
$49.95
3.5
10
S9
$9.95
1.25
11
S10
$10.95
1.5

<tbody>
</tbody>


Name A6:E11 (thus headers included) PTable via the Name Box or FORMULAS | Name Manager.
Did you mean C6:E11?

Would it also work to define the named range as $C:$E? That way if I add rows to the table, I don't have to redefine the range.

Sheet2

Row\Col
H​
I​
J​
K​
6​
Product
Quan
Price
Cost
7​
M44
5
$49.95
$249.75
8​
S10
10
$10.95
$109.50
9​
M28
25
$29.95
$748.75

<tbody>
</tbody>


In J7 enter and copy down:

=VLOOKUP($H7,PTable,MATCH(J$6,INDEX(PTable,1,0),0),0)

In K7 enter and copy down:

=I7*J7
Very nice, thank you

2. Open a new workbook.

Sheet1 of the new workbook:

Row\Col
A​
B​
C​
D​
1​
Product
Quan
Price
Cost
2​
M44
5
$49.95
$249.75
3​
S10
10
$10.95
$109.50
4​
M28
25
$29.95
$748.75

<tbody>
</tbody>


In C2 enter and copy down:

=VLOOKUP($A2,jm.xlsx!PTable,MATCH(C$1,INDEX(jm.xlsx!PTable,1,0),0),0)

In D2 enter and copy down:

=B2*C2

Outstanding. Is this any less efficient than having it in the same workbook? I imagine Excel loads it once and then keeps it in memory.
 
Upvote 0
Sheet1
=VLOOKUP($A2,jm.xlsx!PTable,MATCH(C$1,INDEX(jm.xlsx!PTable,1,0),0),0)

PS: I assume that this requires the jm.xlsx book to be in the same folder as the calling book. If it is in a different folder, do I add the full path before the book name? Do I enclose it in quotes? What if the path contains spaces?

Thanks
 
Upvote 0
Did you mean C6:E11?

Yes, that's what I had in mind.

Would it also work to define the named range as $C:$E? That way if I add rows to the table, I don't have to redefine the range.

That shoul be possible. Note that the MATCH expressions the formulas include expect the headers in the first row.

Very nice, thank you



Outstanding.


You are welcome.

Is this any less efficient than having it in the same workbook? I imagine Excel loads it once and then keeps it in memory.

Yeah. In the same book, there should be no need to have all that in memory I think.

PS: I assume that this requires the jm.xlsx book to be in the same folder as the calling book. If it is in a different folder, do I add the full path before the book name? Do I enclose it in quotes? What if the path contains spaces?

Thanks

Let Excel do all that... Keep both books open while you implement the formulas. Once the formulas in place, you can close the appropriate book.
 
Upvote 0
Let Excel do all that... Keep both books open while you implement the formulas. Once the formulas in place, you can close the appropriate book.

That works amazingly well. I created two workbooks: Book1 with a "source" table containing the master data. Book2 in a different folder containing an "access" table using the formulas you provided. The access table was able to pull any of the data from the source table. I then closed the access workbook, made some changes in the source table and closed it. I then opened the access table and the changes were immediately updated.

Then I got a bit of a surprise. I checked the formulas in the access table. It was humongous. As you said, Excel took care of adding the path to the filename. The resulting formula was 478 characters long! It works, but I would be very reluctant to touch it. :LOL:

It looks like I have gone well past the database capabilities of Excel. I think it is time to learn Access.

Thanks for all the help.
 
Upvote 0
That works amazingly well. I created two workbooks: Book1 with a "source" table containing the master data. Book2 in a different folder containing an "access" table using the formulas you provided. The access table was able to pull any of the data from the source table. I then closed the access workbook, made some changes in the source table and closed it. I then opened the access table and the changes were immediately updated.

Then I got a bit of a surprise. I checked the formulas in the access table. It was humongous. As you said, Excel took care of adding the path to the filename. The resulting formula was 478 characters long! It works, but I would be very reluctant to touch it. :LOL:

:cool:

It looks like I have gone well past the database capabilities of Excel. I think it is time to learn Access.

Or Power Pivot...

Thanks for all the help.

You are welcome.
 
Upvote 0

Forum statistics

Threads
1,214,391
Messages
6,119,244
Members
448,879
Latest member
VanGirl

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