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

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
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,213,520
Messages
6,114,101
Members
448,548
Latest member
harryls

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