My question builds off of the one asked here and the accepted answer:
Find the nearest set of coordinates in Excel
The accepted answer there provides two solutions:
- Non-circular distance:
=LOOKUP(1,1/FREQUENCY(0,MMULT((B$1:C$10-E1:F1)^2,{1;1})),A$1:A$10)
- Circular distance:
=LOOKUP(1,1/FREQUENCY(0,SIN((RADIANS(B$1:B$10-E1))/2)^2+SIN((RADIANS(C$1:C$10-F1))/2)^2*COS(RADIANS(B$1:B$10))*COS(RADIANS(E1))),A$1:A$10)
However, that dataset looks like this:
I'm trying to work with a dataset that looks like the following:
What I'm trying to do is:
- Fill in
G
andH
where they are empty. - If
G
andH
is empty, look atE
andF
(e.g.G2
andH2
are empty, so get the coordinates fromE2
andF2
). - Search all
E
andF
for the next closest coordinates whereG
andH
are not blank. - Return the value of
G
andH
.
All I have so far is modifying the Non-circular solution:
=LOOKUP(1,1/FREQUENCY(0,MMULT(($E$2:$F$69778-E2:F2)^2,{1;1})),$H$2:$H$69778)
Of course with this, it just matches to itself and G
and H
are blank so it returns nothing.
Any suggestions for how to implement this?
As a last resort I can always just copy to a separate tab all of the rows with values in G
and H
and do the lookup against that. Trying to implement it without doing that first however.