OK David - hold on to your hat - here is the answer(s). (I think
)
Find the attached.
1. I made cell E2 the Gate number and the rest of column E is the distance between those coordinates.
2. Look at the formula in E3 and down as:
=SQRT(((B3-VLOOKUP($E$2,$G$3:$J$36,2,FALSE))^2)+((C3-VLOOKUP($E$2,$G$3:$J$36,3,FALSE))^2)+((D3-VLOOKUP($E$2,$G$3:$J$36,4,FALSE))^2))
Which is long winded to go lookup the X,Y,Z gate coordinates based on their number in col G
3. You put in the Gate Number in E3 and all the distances are calculated for that gate.
4. A little VBA Loop supplies the rest. It goes down the gate numbers - putting them in cell E2 and then brings back the Minimum value of all those distances into col K across from the gate number.
Code looks like:
Sub MinOfGates()
Dim LastGateRow As Double
Dim GateCtr As Double
Dim LastSpeedRow As Double
LastGateRow = Cells(Rows.Count, "G").End(xlUp).Row
LastSpeedRow = Cells(Rows.Count, "A").End(xlUp).Row
For GateCtr = 3 To LastGateRow
Range("E2") = Cells(GateCtr, "G")
Application.Calculate
Cells(GateCtr, "K") = WorksheetFunction.Min(Range(Cells(3, "E"), Cells(LastSpeedRow, "E")))
Next GateCtr
End Sub
This is a GREAT example of letting Excel and VBA work together in an efficient way.
See attached. Hope it all helps.
Bookmarks