Results 1 to 7 of 7

Thread: VBA function with 3 arguments in 3 cells to the left of entered cell

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,895
    Location
    I like to use Option Explicit (I need all the help I can get)

    1. I wasn't going to lecture my opinion, but the version below works without Option Explicit, but all the variables (all un-Dim-ed) default to Variant type, and I prefer to have them strongly typed so that if I accidently try to assign a String to a valiable that should only be Long, it'll tell me

    The other reason is that I might make a typo with a variable that takes forever to track down

    sMsg = "This is a bad thing to do"
    
    ...
    ...
    ...
    ...
    ...
    
    If x = 0 then
         Msgbox sMgs
    
    ...
    
    ..
    ..


    Public Function DecDegrees() As Variant
        DecDegrees = CVErr(xlErrNum)
    
        Application.Volatile    '   look in Help
    
        On Error GoTo NiceExit
        
        Set R = Application.Caller  '   cell with this function in
        D = R.Offset(0, -3).Value   '   3 to the left, etc.
        M = R.Offset(0, -2).Value
        S = R.Offset(0, -1).Value
    
    
        'Decimal degrees = degrees + minutes/60 + seconds/ 3600
        DecDegrees = D + M / 60# + S / 3600#    '   # = double i.e. 3600.0 --> 3600#
        
        Exit Function
        
    NiceExit: End Function

    2. You should be able to edit a post to correct a typo (I have to do it all the time since my keyboard insists on making dumb mistakes)

    There should be an [Edit Post] buttom below right
    Last edited by Paul_Hossler; 03-21-2022 at 07:47 PM.
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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