How can I write a VBA code that converts Bearing angle in degrees to Azimuth. For example, (N90E) to (90 degrees) or (S60W) to (300 degrees).
How can I write a VBA code that converts Bearing angle in degrees to Azimuth. For example, (N90E) to (90 degrees) or (S60W) to (300 degrees).
Try this (S60W = 240 doesn't it?):
![]()
Please Login or Register to view this content.
![]()
Please Login or Register to view this content.
Or if you prefer with Select Case.
![]()
Please Login or Register to view this content.
To make this universal you should also include error checks regarding prefix (N or S) and suffix (E or W).
Also for the numeric portion you should add a check being > 0 and < 90.
Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.
I would say that people who know about using directions in quadrant readings should know that there is no such thing as a minus reading.
An error check for just "North", "East", "South" or "West" might be an idea.
We could of course make sure it works on both small letters and capital letters but the OP should be able to add that. If not, he/she can request it
But I do appreciate you taking some time off from firing up the ovens though.
@ bakerman2
Is this what you had in mind?
Or you can have a message box asking if all the readings are true quadrant readings starting with an N or S and ending with an E or W.![]()
Please Login or Register to view this content.
Have not been able to get like above with Select Case yet. Maybe tomorrow because now it is bed time here. Do you have that?
Maybe something like this ?
![]()
Please Login or Register to view this content.
Last edited by bakerman2; 03-14-2017 at 05:26 AM.
@bakerman2
There are multiple ways to skin the proverbial cat.
In my opinion, and it is strictly my personal view, the best way is to have people get used to doing things properly if these bearings are entered by hand. Make sure they use N??E or S??W etc.
If the data is imported, either have something like you showed or change all the non compliance values with a separate macro.
A lot depends on how many data points there are. A macro with two arrays works good for me on something else where names are imported and the spelling is not always the same.
Anyway. It was good "conversing" with you.
Keep up the good work because you are light years ahead of me in coding and I have changed a lot of my macros to yours for the same type problems.
Regards
PS
And we should never forget what Douglas Adams said:
"A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools."
Last edited by jolivanes; 03-14-2017 at 01:29 PM. Reason: Additional info added
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks