LOOKUP - with a difference!

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Hello. I have a problem that I believe is soluble using VBA but I would really prefer a formula approach. This is an example of my sheet with several columns removed for clarity.

<b>Z207</b><br /><br /><table border="1" cellspacing="0" cellpadding="0" style="font-family:Arial,Arial; font-size:10pt; background-color:#ffffff; padding-left:2pt; padding-right:2pt; "> <colgroup><col style="font-weight:bold; width:30px; " /><col style="width:64px;" /><col style="width:59px;" /><col style="width:64px;" /><col style="width:78px;" /><col style="width:64px;" /><col style="width:42px;" /><col style="width:64px;" /><col style="width:64px;" /></colgroup><tr style="background-color:#cacaca; text-align:center; font-weight:bold; font-size:8pt; "><td > </td><td >A</td><td >B</td><td >C</td><td >D</td><td >E</td><td >F</td><td >G</td><td >H</td></tr><tr style="height:17px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >1</td><td >Result</td><td >Easting</td><td >Northing</td><td >SampleDate</td><td >Dist (m)</td><td > </td><td > </td><td > </td></tr><tr style="height:17px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >2</td><td style="text-align:right; ">49.63</td><td style="text-align:right; ">359265</td><td style="text-align:right; ">181460</td><td style="text-align:right; ">10/05/2004</td><td style="text-align:right; ">694</td><td > </td><td style="text-align:right; ">2004</td><td style="text-align:right; ">123</td></tr><tr style="height:17px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >3</td><td style="text-align:right; ">94.68</td><td style="text-align:right; ">361223</td><td style="text-align:right; ">182613</td><td style="text-align:right; ">24/06/2004</td><td style="text-align:right; ">1579</td><td > </td><td style="text-align:right; ">2005</td><td style="text-align:right; ">33</td></tr><tr style="height:17px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >4</td><td style="background-color:#ff0000; text-align:right; ">123</td><td style="text-align:right; ">359850</td><td style="text-align:right; ">181834</td><td style="text-align:right; ">02/08/2004</td><td style="text-align:right; ">0</td><td > </td><td style="text-align:right; ">2006</td><td style="text-align:right; ">80.15</td></tr><tr style="height:17px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >5</td><td style="text-align:right; ">66.1</td><td style="text-align:right; ">360362</td><td style="text-align:right; ">181769</td><td style="text-align:right; ">26/10/2004</td><td style="text-align:right; ">516</td><td > </td><td style="text-align:right; ">2007</td><td style="text-align:right; ">67.3</td></tr><tr style="height:17px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >6</td><td style="text-align:right; ">35.98</td><td style="text-align:right; ">363199</td><td style="text-align:right; ">180609</td><td style="text-align:right; ">29/11/2004</td><td style="text-align:right; ">3566</td><td > </td><td > </td><td > </td></tr><tr style="height:17px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >7</td><td style="text-align:right; ">27.31</td><td style="text-align:right; ">362832</td><td style="text-align:right; ">180672</td><td style="text-align:right; ">23/02/2005</td><td style="text-align:right; ">3200</td><td > </td><td > </td><td > </td></tr><tr style="height:17px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >8</td><td style="text-align:right; ">33</td><td style="text-align:right; ">359355</td><td style="text-align:right; ">181969</td><td style="text-align:right; ">11/04/2005</td><td style="text-align:right; ">513</td><td > </td><td > </td><td > </td></tr><tr style="height:17px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >9</td><td style="text-align:right; ">31.11</td><td style="text-align:right; ">362593</td><td style="text-align:right; ">180297</td><td style="text-align:right; ">25/05/2005</td><td style="text-align:right; ">3144</td><td > </td><td > </td><td > </td></tr><tr style="height:17px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >10</td><td style="text-align:right; ">81.2</td><td style="text-align:right; ">361525</td><td style="text-align:right; ">183027</td><td style="text-align:right; ">06/10/2005</td><td style="text-align:right; ">2056</td><td > </td><td > </td><td > </td></tr><tr style="height:17px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >11</td><td style="text-align:right; ">42.48</td><td style="text-align:right; ">361588</td><td style="text-align:right; ">181688</td><td style="text-align:right; ">15/11/2005</td><td style="text-align:right; ">1744</td><td > </td><td > </td><td > </td></tr><tr style="height:17px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >12</td><td style="text-align:right; ">20.92</td><td style="text-align:right; ">362252</td><td style="text-align:right; ">180143</td><td style="text-align:right; ">31/01/2006</td><td style="text-align:right; ">2938</td><td > </td><td > </td><td > </td></tr><tr style="height:17px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >13</td><td style="text-align:right; ">48.55</td><td style="text-align:right; ">361353</td><td style="text-align:right; ">181673</td><td style="text-align:right; ">27/07/2006</td><td style="text-align:right; ">1512</td><td > </td><td > </td><td > </td></tr><tr style="height:17px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >14</td><td style="text-align:right; ">139.6</td><td style="text-align:right; ">363038</td><td style="text-align:right; ">180926</td><td style="text-align:right; ">13/09/2006</td><td style="text-align:right; ">3315</td><td > </td><td > </td><td > </td></tr><tr style="height:17px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >15</td><td style="text-align:right; ">80.15</td><td style="text-align:right; ">360326</td><td style="text-align:right; ">181898</td><td style="text-align:right; ">03/11/2006</td><td style="text-align:right; ">480</td><td > </td><td > </td><td > </td></tr><tr style="height:17px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >16</td><td style="text-align:right; ">32.93</td><td style="text-align:right; ">360802</td><td style="text-align:right; ">181710</td><td style="text-align:right; ">11/12/2006</td><td style="text-align:right; ">960</td><td > </td><td > </td><td > </td></tr><tr style="height:17px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >17</td><td style="text-align:right; ">23</td><td style="text-align:right; ">362232</td><td style="text-align:right; ">181339</td><td style="text-align:right; ">25/01/2007</td><td style="text-align:right; ">2433</td><td > </td><td > </td><td > </td></tr><tr style="height:17px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >18</td><td style="text-align:right; ">22.6</td><td style="text-align:right; ">365264</td><td style="text-align:right; ">181066</td><td style="text-align:right; ">06/03/2007</td><td style="text-align:right; ">5468</td><td > </td><td > </td><td > </td></tr><tr style="height:17px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >19</td><td style="text-align:right; ">39.7</td><td style="text-align:right; ">362376</td><td style="text-align:right; ">180837</td><td style="text-align:right; ">25/04/2007</td><td style="text-align:right; ">2716</td><td > </td><td > </td><td > </td></tr><tr style="height:17px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >20</td><td style="text-align:right; ">67.3</td><td style="text-align:right; ">359849</td><td style="text-align:right; ">181418</td><td style="text-align:right; ">07/06/2007</td><td style="text-align:right; ">416</td><td > </td><td > </td><td > </td></tr><tr style="height:17px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >21</td><td style="text-align:right; ">22.6</td><td style="text-align:right; ">361283</td><td style="text-align:right; ">181706</td><td style="text-align:right; ">14/12/2007</td><td style="text-align:right; ">1439</td><td > </td><td > </td><td > </td></tr></table><br /><table style="font-family:Arial; font-size:10pt; border-style: groove ;border-color:#00ff00;background-color:#fffcf9; color:#000000; "><tr><td ><b>Spreadsheet Formulas</b></td></tr><tr><td ><table border = "1" cellspacing="0" cellpadding="2" style="font-family:Arial; font-size:9pt;"><tr style="background-color:#cacaca; font-size:10pt;"><td >Cell</td><td >Formula</td></tr><tr><td >E2</td><td >=SQRT(<span style=' color:008000; '>(B2-B$4)</span>^2+<span style=' color:008000; '>(C2-C$4)</span>^2)</td></tr></table></td></tr></table> <br />Excel tables to the web - Excel Jeanie Html 4


What I have done here manually is as follows.

1) Identified the highest result (column A) occurring in 2004.

2) Calculated the distance between each sample point (formulas in column E) and the point identified in 1)

3) For each year 2005, 2006, 2007 found the result in column A corresponding to the closest point (i.e. smallest distance) compared to the sample identified in 1)

4) Filled in the matching values in columns G and H.

Is this even possible using a formula :confused:

I've done half a dozen of these by hand but I think that my client may want many (hundreds :nervous:) more.

Thanks in advance.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Is it OK to add a new column to extract the year part of the sample date? If so, assuming the new year column is in D and the others are shifted one across accordingly, then I would use:
in I1, array-entered: =MATCH(MAX(IF($D$1:$D$21=2004,$A$1:$A$21,"")),IF($D$1:$D$21=2004,$A$1:$A$21,""),0)
In F2 (Dist column): =SQRT((B2-INDEX(B:B,$I$1))^2+(C2-INDEX(C:C,$I$1))^2)
and copy down
In I4 (the 2004 match) array-entered: =INDEX(A:A,MATCH(MIN(IF($D$1:$D$21=H2,$F$1:$F$21,"")),IF($D$1:$D$21=H2,$F$1:$F$21,""),0))
and copy down.
Does that help at all?
 
Upvote 0
Just as a simple (if not eligant) solution... I'd insert a date column (A:A) =year(sampledate)
Then I'd sort the table by year/distance
Then for G:H (which'd become H:I because of the insert of column A:A, i would put I2 =VLOOKUP(H2,$A$2:$F$21,2,FALSE) .. it'll find the first (i.e. largest) by year.

Alternatively, you can put a pivot table in, and select MIN(dist(m)) as your data points, but you'd still need that 'year' column.

Sorry can't think of anything more eligant right now.
 
Upvote 0
Hi Vog II:

following is one way using one-varible DataTable ...

<html><head><title>Excel Jeanie HTML</title></head><body>
Excel Workbook
ABCDEFGHIJK
1ResultEastingNorthingSampleDateDist (m)123
249.6335926518146010/5/20046942004123FALSE
394.6836122318261324/06/20041579200533
41233598501818342/8/20040200680.15
566.136036218176926/10/2004516200767.3
635.9836319918060929/11/20043566database
727.3136283218067223/02/20053200criteriaRange
83335935518196911/4/2005513dataTable_columNinputCell
931.1136259318029725/05/20053144dataTable_formulaCell
1081.23615251830276/10/20052056dataTable: G1:H5
1142.4836158818168815/11/20051744
1220.9236225218014331/01/20062938
1348.5536135318167327/07/20061512
14139.636303818092613/09/20063315
1580.153603261818983/11/2006480
1632.9336080218171011/12/2006960
172336223218133925/01/20072433
1822.63652641810666/3/20075468
1939.736237618083725/04/20072716
2067.33598491814187/6/2007416
2122.636128318170614/12/20071439
Sheet3


</body></html>
Would this do?
 
Last edited:
Upvote 0
Thanks Eugene and Yogi for those alternatives.

I should have explained that I only posted part of the data for 1 'zone'. I actually have up to about 200 zones per sheet, and 26 sheets. With that layout it is much easier to use Rory's formulas to the right of the existing columns.

Thanks again :)
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

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