+ Reply to Thread
Results 1 to 10 of 10

VBA code that converts Bearing angle in degrees to Azimuth

  1. #1
    Registered User
    Join Date
    03-13-2017
    Location
    676
    MS-Off Ver
    EXCEL 2013
    Posts
    2

    Smile VBA code that converts Bearing angle in degrees to Azimuth

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

  2. #2
    Valued Forum Contributor
    Join Date
    11-26-2012
    Location
    Sydney
    MS-Off Ver
    2010
    Posts
    423

    Re: VBA code that converts Bearing angle in degrees to Azimuth

    Try this (S60W = 240 doesn't it?):

    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,700

    Re: VBA code that converts Bearing angle in degrees to Azimuth

    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,700

    Re: VBA code that converts Bearing angle in degrees to Azimuth

    Or if you prefer with Select Case.
    Please Login or Register  to view this content.

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,350

    Re: VBA code that converts Bearing angle in degrees to Azimuth

    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.

  6. #6
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,700

    Re: VBA code that converts Bearing angle in degrees to Azimuth

    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.

  7. #7
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,700

    Re: VBA code that converts Bearing angle in degrees to Azimuth

    @ bakerman2
    Is this what you had in mind?

    Please Login or Register  to view this content.
    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.

    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?

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,350

    Re: VBA code that converts Bearing angle in degrees to Azimuth

    Maybe something like this ?

    Please Login or Register  to view this content.
    Last edited by bakerman2; 03-14-2017 at 05:26 AM.

  9. #9
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,700

    Re: VBA code that converts Bearing angle in degrees to Azimuth

    @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

  10. #10
    Registered User
    Join Date
    03-13-2017
    Location
    676
    MS-Off Ver
    EXCEL 2013
    Posts
    2

    Re: VBA code that converts Bearing angle in degrees to Azimuth

    Thank you very much, you helped me a lot.
    So and if I wanted to change it from Azimuth to Bearing what should I do.
    God Bless You,

    Quote Originally Posted by bakerman2 View Post
    Maybe something like this ?

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 4
    Last Post: 07-26-2016, 09:06 AM
  2. Convert Angle (Azimuth) to Bearing format.
    By markogwapito in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-13-2015, 06:59 AM
  3. Replies: 2
    Last Post: 05-04-2013, 07:33 AM
  4. Converting Lat/Long (Degrees Minutes Seconds) to Decimal Degrees
    By Jeremy Rayne in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-24-2008, 06:02 PM
  5. Replies: 2
    Last Post: 04-28-2006, 07:20 AM
  6. Plot R-Theta [angle (0~360 degrees) and amplitude] chart in Excel
    By Wes12 in forum Excel Charting & Pivots
    Replies: 6
    Last Post: 01-28-2006, 08:35 PM
  7. [SOLVED] convert an angle to degrees minutes seconds
    By Mac in forum Excel General
    Replies: 1
    Last Post: 03-22-2005, 12:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1