## Sub or function not defined error on ArcCos

cos inverse in excel

excel acos

how to write cos inverse in vba

I'm trying to create a function in Excel to calculate the distance between two points in latitude longitude.

This function gives me the error

Compile error:

Sub or function not defined

Function DAVIDLATLON(lat1, lon1, lat2, lon2) DAVIDLATLON = ArcCos(Cos(Application.WorksheetFunction.Radians(90 - lat1)) * Cos(Application.WorksheetFunction.Radians(90 - lat2)) + Sin(Application.WorksheetFunction.Radians(90 - lat1)) * Sin(Application.WorksheetFunction.Radians(90 - lat2)) * Cos(Application.WorksheetFunction.Radians(lon1 - lon2))) * 6371 End Function

The problem is with the arc-cosine function. Try:

Function DAVIDLATLON(lat1, lon1, lat2, lon2) With Application.WorksheetFunction DAVIDLATLON = .Acos(Cos(.Radians(90 - lat1)) * Cos(.Radians(90 - lat2)) + Sin(.Radians(90 - lat1)) * Sin(.Radians(90 - lat2)) * Cos(.Radians(lon1 - lon2))) * 6371 End With End Function

**Acos Function not defined,** When I try to put it in a Sub it breaks on Acos with an error message Sub or Function not defined. If I take out Acos and only use Sin Cos A Sub or Function must be defined in order to be called. Possible causes of this error include: Misspelling the procedure name. Trying to call a procedure from another project without explicitly adding a reference to that project in the References dialog box. Specifying a procedure that is not visible to the calling procedure.

There is no native VBA ArcCos function. Use `worksheetfunction.acos`

instead.

Function DAVIDLATLON(lat1, lon1, lat2, lon2) DAVIDLATLON = WorksheetFunction.Acos(Cos(WorksheetFunction.Radians(90 - lat1)) * _ Cos(WorksheetFunction.Radians(90 - lat2)) + _ Sin(WorksheetFunction.Radians(90 - lat1)) * _ Sin(WorksheetFunction.Radians(90 - lat2)) * _ Cos(WorksheetFunction.Radians(lon1 - lon2))) * 6371 End Function

**Sub or function not defined error on ArcCos,** Sub or function not defined error on ArcCos. acos vba sub or function not defined vba visual basic acos pi vba excel acos cos inverse in excel how to write cos The Acos function is not defined by VBA, but by Excel, so, you should use it like Answer = Application.Worksheetfunction.Acos(Argument) or just

Since the ArcCos Function is not known by VBA my understanding is you could first define the ArcCos function and then reference it from your second function.

Function ArcCos(RadAngle) ArcCos = Atn(-RadAngle / Sqr(-RadAngle * RadAngle + 1)) + 2 * Atn(1) End Function Function DAVIDLATLON(Lat1, Lon1, Lat2, Lon2) DAVIDLATLON = ArcCos(Cos(Application.WorksheetFunction.Radians(90 - Lat1)) * Cos(Application.WorksheetFunction.Radians(90 - Lat2)) + Sin(Application.WorksheetFunction.Radians(90 - Lat1)) * Sin(Application.WorksheetFunction.Radians(90 - Lat2)) * Cos(Application.WorksheetFunction.Radians(Lon1 - Lon2))) * 6371 End Function

**ACOS 'Sub or Function Not Defined',** vba (2003) and I can see the ACOS function in the vba. HELP, but I can't use it. At runtime it fails with a "Sub Or Function not defined" error. 1. Open the Microsoft Visual Basic development environment associated with the version of Excel you are using. Typically, you can browse in Excel by going to the 'Developer' Tab and click on the 'Visual Basic' icon (possibly the first icon on the left).

**Sub or function not defined error on ArcCos,** Sub or function not defined error on ArcCos. Я пытаюсь создать функцию в Excel, чтобы вычислить расстояние между двумя точками в широте и долготе. Since the ArcCos Function is not known by VBA my understanding is you could first define the ArcCos function and then reference it from your second function.

**Excel VBA Question - re: Arccos,** Function ArcCos(x As Single) As Single 'Calculates the arc cosine of x (in End Function Sub Calc_RangeFinder() 'Subroutine for Range I'm not going to check your math, but the reason(s) you're getting the error are 1) you're calling So any VBA function used as a user-defined function called from cell formulas *will* Sub DoNotClearCells2() 'PURPOSE: Clear out all cells that do not contain a specific word/phrase Dim rng As Range Dim cell As Range Dim ContainWord As String Sub or Function Not Defined [SOLVED] Help

**Sub or Function not defined,** A Sub or Function must be defined in order to be called. Possible causes of this error include: Misspelling the procedure name. Trying to call a Select a Web Site. Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

##### Comments

- I prefer the use of the WITH