+ Reply to Thread
Results 1 to 4 of 4

VBA UDF Value Error

  1. #1
    Registered User
    Join Date
    09-27-2016
    Location
    Syracuse, NY
    MS-Off Ver
    MS Office 2016
    Posts
    2

    VBA UDF Value Error

    Hello everyone:

    I am new to the forum. I am also new to VBA. I admit I am still learning but thought I would be able to do this relatively easily. What I have created is a UDF that helps me calculate the distance between two geographic locations based on latitude and longitude values as arguments.

    So far I have not been able to solve the problem with it because it keeps giving me a #VALUE! error. I don't know if it's something simple I am missing or not. Below is my code for the UDF provided for you.

    Please Login or Register  to view this content.
    I would greatly appreciate whatever help I can get from you.

    Thank you for your time and consideration.

    S. Thompson

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: VBA UDF Value Error

    Welcome to the board.

    A
    B
    C
    D
    E
    F
    G
    H
    1
    Apt1
    Lat1
    Lon1
    Apt2
    Lat2
    Lon2
    Dist
    2
    DFW
    32.8968
    -97.0398
    SJC
    37.3667
    -121.9333
    1,436
    G2: =3959 * CentralAngle(B2, C2, E2, F2)


    Please Login or Register  to view this content.
    Last edited by shg; 09-27-2016 at 09:55 AM.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Valued Forum Contributor Neil_'s Avatar
    Join Date
    04-19-2013
    Location
    Yorkshire
    MS-Off Ver
    Office 365 Enterprise E3 2013 / 2016
    Posts
    479

    Re: VBA UDF Value Error

    Don't know anything about longitude and latitude, but as you are treating them as Doubles, then they must just be numbers, so...

    Please Login or Register  to view this content.
    as you are subtracting latitude1 from itself then this reads as g = 0 / 2, so at this point will always =0

    Please Login or Register  to view this content.
    As you have a zero in there (g * g), C1 will always be zero too, as you are multiplying by zero.

    Please Login or Register  to view this content.
    The function breaks here with a division by zero error. Shoot me if I'm wrong, I don't do maps.
    Frob first, tweak later

  4. #4
    Registered User
    Join Date
    09-27-2016
    Location
    Syracuse, NY
    MS-Off Ver
    MS Office 2016
    Posts
    2

    Re: VBA UDF Value Error

    SHG:

    Thanks a ton! It works perfectly now!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA ERROR: run time error 1004: Application-defined or Object-defined error in excel 2013
    By AnanthKrishna in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-13-2015, 06:16 AM
  2. [SOLVED] Run-tim error -2147467259(80004005): Automation error Unspecidied error
    By mattress58 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-25-2014, 12:12 PM
  3. Excel macro (compile error. syntax error.) error
    By salar_younis in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-06-2014, 06:11 AM
  4. Receiving following error “Complie error : syntax error” Help
    By masond3 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-02-2012, 10:19 AM
  5. Error "run-time Error '1004': General Odbc Error
    By D4WNO77 in forum Access Tables & Databases
    Replies: 2
    Last Post: 07-16-2012, 09:55 AM
  6. Error 75 File/Path access error, sometimes Error 1004
    By smokebreak in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 02-16-2011, 02:35 PM
  7. Error Handling - On Error GoTo doesn't trap error successfully
    By David in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-16-2006, 02:10 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1