View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Translating spreadsheet formula to VBA

I did show you.

Yes, TAN and ATN are two different functions

? format(cos(tan(1)),"0.00000")
0.01339
? format(cos(atn(1)),"0.00000")
0.70711



Regards,
Tom Ogilvy

Sheela wrote in message
...
Yea, it worked but what is another way of doing it? Can
you show me how to use the function with Atan. Technicaly
speaking, I don't know how this formula works. I'm doing
this assignment for another person.

The answer should display 0.978 but its displaying 0.977.
Does Tan and Atan makes a little difference?

Thanks,

Sheela

-----Original Message-----
sure you are getting the right answer.

Patrick offered:
Function MyATAN(V1 As Double, V2 As Double) As Double
Dim first As Double
Application.Volatile
first = Tan(V1 / V2)
MyATAN = Cos(first)
End Function

But that is using the Tangent with two arguments.

Shouldn't it be (based on =COS(ATAN(E13/E14)) )

Function MyATAN(V1 As Double) As Double
Dim first As Double
Application.Volatile
first = ATN(V1)
MyATAN = Cos(first)
End Function

so
Textbox1.Text = Format$(MyATAN(Range("E13")/Range

("E14"),"0.0")


Regards,
Tom Ogilvy


"Sheela" wrote in message
...
Dear Patrick,

Thank you very much for your help. It worked!!

Rgrds,
Sheela

-----Original Message-----
Your question bears no relation to your initial

question.

In a sheet use =MyAtan(A1,A2)
replacing MyAtan with your function name and A1 and A2
by
whatever cell references you want.
In VB

MyResult = MyAtan(Var1,Var2)


If you wnat the result in a textbox on a userform then
Textbox1.Text = Format$(MyResult,"0.0")

HTH
Patrick Molloy
Microsoft Excel MVP



-----Original Message-----
Hello,

Thanks for your help. I guess I can use the first
function. How do I call this function to that
particular
textbox. I'm not linking VB with the spreadsheet but

I
have designed a form using the dialog box and when I
run
excel, it will popup this form.

My question is, can I use the VB function which was
suggested to me or is there another way of doing it?

Thanks.

Sheela


-----Original Message-----
First, check HELP for the correct functions.
Generally, you could use EITHER the VB function OR

the
Worksheet function, so check them both out.

1) Using the VB function
Function MyATAN(V1 As Double, V2 As Double) As

Double
Dim first As Double
Application.Volatile
first = Tan(V1 / V2)
MyATAN = Cos(first)
End Function

2) Using the worksheet function
Function MyATAN(V1 As Double, V2 As Double) As

Double
Dim first As Double
Application.Volatile
first = Application.WorksheetFunction.Atan2(V1,

V2)
MyATAN = Application.WorksheetFunction.Cosh
(first)
End Function


Patrick Molloy
Microsoft Excel MVP

-----Original Message-----
I have this formula in worksheet:

=COS(ATAN(E13/E14))

I want to create this formula in VBA but its not
available in the library.

I'm new to this VBA. I'll really appreciate if
anybody
could help me out in this.

Thanks.

Sheela
.

.

.

.



.