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


New Member
Feb 26, 2019
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!



Kenneth Hobson

Well-known Member
Feb 6, 2007
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.
Sub CountLatLongLimits()
  MsgBox CountLLL(25#, CDbl([C2].Value), CDbl([B2].Value), Range("H2:H10"))
End Sub

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
    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:


New Member
Feb 26, 2019
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!

Forum statistics

Latest member

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...