Formula Help Involving Comparing Distance With Lat. Long. Reference Points

GCarpenter

New Member
Joined
Feb 26, 2019
Messages
4
Hello Everyone,

I'm stumped on this one...

Would anyone know a formula that would return the values shown in the example attached?

I'm trying to find out how many people live within 25 miles and within 50 miles of a store, but my reference points are lat.long. coordinates.

Any help would be greatly appreciated!

Thanks

example.jpg



 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Kenneth Hobson

Well-known Member
Joined
Feb 6, 2007
Messages
3,180
Office Version
  1. 365
Platform
  1. Windows
Welcome to the forum!

Install Chip Pearson's routine as commented into a Module and my routine at the end or in another Module. Use my function to suit as shown in test sub or commented UDF.
Code:
Sub CountLatLongLimits()
  MsgBox CountLLL(25#, CDbl([C2].Value), CDbl([B2].Value), Range("H2:H10"))
End Sub

'=CountLLL(25,C2,B2,H2:H11)
Function CountLLL(L As Double, lat1 As Double, lon1 As Double, rLatLon As Range) As Double
  Dim d As Double, gcd As Double, c As Range
  Application.Volatile (True)
  For Each c In rLatLon
     'http://www.cpearson.com/excel/LatLong.aspx
    gcd = GreatCircleDistance(lat1, lon1, c.Value, c.Offset(, 1).Value, True, True)
    'Debug.Print c.Address, gcd
    If gcd <= L Then d = d + 1
  Next c
  CountLLL = d
End Function
 
Last edited:

GCarpenter

New Member
Joined
Feb 26, 2019
Messages
4
Worked perfectly...thank you!!

I do have one more question though if you don't mind.

I need to run the same counts but instead of "within 25 miles" I need "within a 30 min drive"

Is there a routine built for calculating distance in "time" (I'm guessing via Google maps), instead of "miles"?

Thanks in advance!
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,559
Messages
5,832,498
Members
430,136
Latest member
Asir Jefferson

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
Top