"End If Without Block If" in Calculate Angle Of TAN

Do Vo Anh

New Member
Joined
May 28, 2015
Messages
6
Can anyone help me solve these problem?:confused::confused::confused::confused:


Sub Calculate()
Dim i As Long
Dim ia As Long
Dim xrad As Double
Dim DistanceOfX As Double
Dim DistanceOfY As Double
Dim Atan As Double
Range("A43:A83").Value = DistanceOfX
If Range("B43:B83").Value = 2.875 Then DistanceOfY = -1.375
End If


xrad = -(2.25 - (DistanceOfY * DistanceOfY)) / (DistanceOfX * DistanceOfY)


Atan = (Atn(xrad)) / 2


Range("E43:E83").Value = Atan


End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Can anyone help me solve these problem?:confused::confused::confused::confused:

If Range("B43:B83").Value = 2.875 Then DistanceOfY = -1.375
End If
There are two forms of If..Then, a single line one that looks like this...

If {logical expression} Then {action statement}

and the other that looks like this...

If {logical expression} Then
{action statements}
End If

In the above part of your code, your If..Then is of the single line kind, so the End If on the next line does not have an If..Then partner, and so it generates an error. You should remove it.
 
Upvote 0
So how can i solve these problem sir? I want to calculate the angle of tan using that formula ( xrad = -(2.25 - (DistanceOfY * DistanceOfY)) / (DistanceOfX * DistanceOfY) )

All Values of DistanceOfX, DistanceOfX in the same Range. But the Value of DistanceOfY has the same value, but i cant use this in my calculate so thats why i'm changing it to another Value that can be use.. So how can i do it, sir?
 
Upvote 0
I am not 100% sure what that code is supposed to be doing, but I so see another problem with your code. This line cannot work...

If Range("B43:B83").Value = 2.875 Then DistanceOfY = -1.375

because you are asking if 41 things are equal to one thing. Are you trying to set DistanceOfY equal to -1.375 if any cell in range B43:B83 equals 2.875? If so, you would need to do that like this...
Code:
If Not Range("B43:B83").Find(2.875, , , xlWhole) Is Nothing Then  DistanceOfY = -1.375
 
Upvote 0

Forum statistics

Threads
1,203,472
Messages
6,055,612
Members
444,803
Latest member
retrorocket129

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top