![]() |
Function ACOS in Excel VBA
Does anybody know if there is an equivalent function in excel VBA like
"ACOS()" in Excel worksheet. Thanks |
Function ACOS in Excel VBA
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 "mario" wrote: Does anybody know if there is an equivalent function in excel VBA like "ACOS()" in Excel worksheet. Thanks |
Function ACOS in Excel VBA
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 "mario" wrote in message ... Does anybody know if there is an equivalent function in excel VBA like "ACOS()" in Excel worksheet. Thanks |
All times are GMT +1. The time now is 12:29 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com