# Calculated Angles Need to be between 0 and 360 Degrees

#### Gordon K

##### Board Regular
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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
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:
Thank you.

Replies
4
Views
563

1,196,250
Messages
6,014,236
Members
441,808
Latest member
xplainer

### 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.

### Which adblocker are you using?

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

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