Function ACOS in Excel VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Does anybody know if there is an equivalent function in excel VBA like
"ACOS()" in Excel worksheet.

Thanks
 
I don't see it but you can use the excel function in vba, as in the following
example that I snipped from VBA help:

Sub UseFunction()
Dim myRange As Range
Set myRange = Worksheets("Sheet1").Range("A1:C10")
answer = Application.WorksheetFunction.Min(myRange)
MsgBox answer
End Sub

I think if you change Min to Acos it should work.

You can get a list of excel functions available to VBA by searching VBA help
on "using excel functions".

Hope this helps.

Keith
 
There's no VB equivalent. You can call Excel's ACOS worksheet function but
it's probably faster to roll your own VB function. Take your pick -

Sub test()
Dim cv As Double, radians As Double
cv = 0.5 ' test with multiple values -1 to +1

radians = fnACOS(cv)
MsgBox Application.WorksheetFunction.acos(cv) & vbCr & _
radians & vbCr & _
cv & vbCr & _
Cos(radians)

End Sub

Function fnACOS(CosVal As Double) As Double
Dim rad As Double
Const pi As Double = 3.14159265358979

If CosVal = 0 Then
' avoid div/0 error
'rad = Atn(1000000000000#)
'or
rad = 1.5707963267949
Else
rad = Atn(Sqr(1 - CosVal ^ 2) / CosVal)
If CosVal < 0 Then
rad = pi + rad
End If
End If

fnACOS = rad

End Function

regards,
Peter T
 
A&A - PRESTAÇÃO DE SERVIÇO.

Melhore suas planilhas!

- Deixe-as mais rápidas
- Torne-as mais funcionais
- Aplique lay-outs mais modernos
- Melhore a apresentação dos seus dados
- impressione os gerentes e a diretoria

Crie o seu M.I.S. personalizado, desenvolva um Dataware, implemente
seu BI.

- Envie dados do seu Banco de Dados
diretamente para a sua aplicação

- Recolha informações diretamente da
Web (Cotações, Taxas, Alíquotas, etc...)

Programação VBA, Reports, Dashboards, Pivot Tables (Tabelas
Dinâmicas), Ordenações, Agrupamentos, Interfaces, etc. . .

Entre em contato. Prestamos serviço diretamente pela Internet.

Você envia e implementamos sua solicitação.

Também desenvolvemos aplicações MS Access.

Mail: (e-mail address removed)
 
Back
Top