adding subtracting angles/degrees

J

Jimmy

Hi guys/gals,

I am trying to figure out how to add and subtract two degrees. I am
speaking about compass/directional degrees (or angles if you prefer).

I need to be able to subtract lets say 45 degrees from a heading/angle
of 020 and arrive at the appropriate result. In this case 335.


Also how can I display the result or format the field to display a
leading "zero" ie 020.

Thanks in advance
 
C

Chip Pearson

Jimmy,

Try the following functions

Function AddDegrees(X As Double, Y As Double) As Double
AddDegrees = (X + Y) Mod 360
End Function
Function SubtractDegrees(X As Double, Y As Double) As Double
SubtractDegrees = (X - Y) - ((X - Y < 0) * 360)
End Function

You can use a custom number format of "000" to preserve the
leading zero.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com (e-mail address removed)
 
R

Ron Rosenfeld

Hi guys/gals,

I am trying to figure out how to add and subtract two degrees. I am
speaking about compass/directional degrees (or angles if you prefer).

I need to be able to subtract lets say 45 degrees from a heading/angle
of 020 and arrive at the appropriate result. In this case 335.


Also how can I display the result or format the field to display a
leading "zero" ie 020.

Thanks in advance

I think this will work as a worksheet formula:

=MOD(Heading+Change,360)

To subtract, enter Change as a negative number.

=mod(20 + (-45),360) --> 335

Format/Cells/Number/Custom Type: 000
or, if you want to be fancy, 000\°

To insert the degree sign, hold down the <alt> key while typing -- on the
NUMERIC KEYPAD -- 0176.


--ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top