Write a macro in VBA excel that converts an azimuth in degre
Write a macro in VBA excel that converts an azimuth in degrees to a bearing in degrees minutes and seconds. Use message boxes to input and output data. The input message box must state that the input data should be from 0 to 360 Degrees. Validate with a block of statements the input data to assure that the input is not less than zero or greater than 360 degrees. Output should be in the format: N 36.5°E or if the azimuth is exactly 0, 90, 180, 270, or 360, the output should be Due North, Due East, Due South, Due West, or Due North, respectively. Place a \"RUN\" button on the spreadsheet. Place appropriate comments throughout your code.
Solution
Sub AzimuthToBearing()
 Dim varInput As Variant
 Dim strOutput As String
   
   
 Do
 varInput = InputBox(\"Enter a value between 0 and 360\")
 If varInput = \"\" Then Exit Sub
 Loop Until varInput >= 0 And varInput <= 360
   
 If varInput = 0 Or varInput = 360 Then
 strOutput = \"Due North\"
 ElseIf varInput = 90 Then
 strOutput = \"Due East\"
 ElseIf varInput = 180 Then
 strOutput = \"Due South\"
 ElseIf varInput = 270 Then
 strOutput = \"Due West\"
 ElseIf varInput > 0 And varInput < 90 Then
 strOutput = \"N \" & varInput & \" \" & Chr(176) & \"E\"
 ElseIf varInput > 90 And varInput < 180 Then
 strOutput = \"E \" & varInput & \" \" & Chr(176) & \"S\"
 ElseIf varInput > 180 And varInput < 270 Then
 strOutput = \"S \" & varInput & \" \" & Chr(176) & \"W\"
 ElseIf varInput > 270 And varInput < 360 Then
 strOutput = \"W \" & varInput & \" \" & Chr(176) & \"N\"
 End If
 
 MsgBox strOutput, , \"Result\"
 End Sub

