Calculated Angles Need to be between 0 and 360 Degrees

Gordon K

Board Regular
Joined
Jan 18, 2009
Messages
56
I am using a VBA macro to extract info from spreadsheet cells operate on them and return the values to a spreadsheet. Each odd numbered item is an angle. The following code works just fine. Is there a way to use a procedure or function to assure the number passed to the cell named Range("item31") is between 0 and 360 degrees.


Range("item30") = Range("item26") * Range("item2")
Range("item31") = Range("item27") + Range("item3")
If Range("item31") < 0 Then Range("item31") = Range("item31") + 360
If Range("item31") > 360 Then Range("item31") = Range("item31") - 360

I did not have any success with the following approach.

MyFunction(Range("item31")) = Range("item27") + Range("item3")
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
If Item27 and Item3 are both angles in degrees between 0 and 360, you could just use

Code:
Range("item31") = (Range("item27") + Range("item3")) Mod 360

If you want to be super complete

Code:
Range("item31") = (Range("item27") + Range("item3") + WorksheetFunction.Ceiling(Abs(Range("item27"), 360) +WorksheetFunction.Ceiling(Abs(Range("Item3")), 360))) Mod 360
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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