Trig problems in VBA 
Author Message
 Trig problems in VBA

I want to use Asin in VBA and I keep getting a sub or function not defined error.
I have the same problem with Degrees.

How can I convert the Sin to Asin if this method is not available. Then how can I
convert to degrees ??

It was told that their is no Radians function and that I should make one.

This is what I did.

Const Pi = 3.1416

Function Rads(Degs as Double) As Double
    Rads = Degs * 0.01745    'degs * (pi/180)
End Function

Here is my code :

  If Sheet1.Cells(3, 8) And Sheet1.Cells(5, 8) <> "" Then
        Number = Sin(Rads(Sheet1.Cells(3, 8) / Sheet1.Cells(5, 8)))
        Sheet1.Cells(9, 8) = Number
   End If

I'm not very good with math so I would appreciate if you take that into
consideration.

jon



Wed, 18 Jun 1902 08:00:00 GMT  
 Trig problems in VBA
Jon
Many worksheet functions are available in VBA.  Usually the ones that are
not available are duplicated by VBA functions.  In this case, however, the
worksheetfunctions are available:

Application.Degrees(Application.Asin(.5))
 returns  30
Application.Degrees(Application.Radians(30))
 Returns 30
Application.Pi()
Returns  3.14159265358979

Sin is available directly,

Degrees, Radian, Pi, Asin are available in VBA as methods of the Application
Object.

HTH,
Tom Ogilvy

Quote:

>I want to use Asin in VBA and I keep getting a sub or function not defined
error.
>I have the same problem with Degrees.

>How can I convert the Sin to Asin if this method is not available. Then how
can I
>convert to degrees ??

>It was told that their is no Radians function and that I should make one.

>This is what I did.

>Const Pi = 3.1416

>Function Rads(Degs as Double) As Double
>    Rads = Degs * 0.01745    'degs * (pi/180)
>End Function

>Here is my code :

>  If Sheet1.Cells(3, 8) And Sheet1.Cells(5, 8) <> "" Then
>        Number = Sin(Rads(Sheet1.Cells(3, 8) / Sheet1.Cells(5, 8)))
>        Sheet1.Cells(9, 8) = Number
>   End If

>I'm not very good with math so I would appreciate if you take that into
>consideration.

>jon



Wed, 18 Jun 1902 08:00:00 GMT  
 Trig problems in VBA
Try something like this

sub trig()
Sheets("SHEET1").Select 'SELECT THER SHERT YOUR USING
Cells(3, 8).Value = 34  'ENTERS SOME TEST VALUES IN THE SHEET TO CHECK
 THE ROUTINE
Cells(5, 8).Value = 56
  If Cells(5, 8).Value And Cells(5, 8).Value <> "" Then
        Number = Sin(Rads(Cells(3, 8).Value / Cells(5, 8).Value))
        Cells(9, 8).Value = Number
   End If
end sub




Wed, 18 Jun 1902 08:00:00 GMT  
 Trig problems in VBA
Jon,

Even better try this

Function Rads(Degs As Double) As Double
    Rads = Degs * 0.01745    'degs * (pi/180)
End Function

Sub TRIG()
Dim sheet1 As Object
Set sheet1 = Sheets("sheet1")
  If sheet1.Cells(5, 8).Value And sheet1.Cells(3, 8).Value = 22 <> ""
Then
        Number = Sin(Rads(sheet1.Cells(3, 8).Value / sheet1.Cells(5,
8).Value))
        sheet1.Cells(9, 8).Value = Number
   End If

End Sub

I hope this is of some help




Wed, 18 Jun 1902 08:00:00 GMT  
 Trig problems in VBA
Jon,

Many apologies my reply to your vba query should have read

Function Rads(Degs As Double) As Double
    Rads = Degs * 0.01745    'degs * (pi/180)
End Function

Sub TRIG()
Dim sheet1 As Object
Set sheet1 = Sheets("sheet1")
  If sheet1.Cells(5, 8).Value <> "" And sheet1.Cells(3, 8).Value  <> ""
Then
        Number = Sin(Rads(sheet1.Cells(3, 8).Value / sheet1.Cells(5,
8).Value))
        sheet1.Cells(9, 8).Value = Number
   End If

End Sub

again many apologies.




Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Trig Function Problems

2. Trig an e-mail

3. Simple Excel Trig Question

4. EXCEL Trig Calc

5. Excel Sheet - Trig functions

6. Auto_Close() can not be trigged before the IE report the chaged message

7. Simple Excel Trig Question

8. trig??

9. NEED HELP WITH TRIG

10. which form event to trig on?


 
Powered by phpBB® Forum Software © phpBB Group