Article ID: 121944
Article Last Modified on 10/11/2006
Function Convert_Degree(Decimal_Deg) As Variant
With Application
'Set degree to Integer of Argument Passed
Degrees = Int(Decimal_Deg)
'Set minutes to 60 times the number to the right
'of the decimal for the variable Decimal_Deg
Minutes = (Decimal_Deg - Degrees) * 60
'Set seconds to 60 times the number to the right of the
'decimal for the variable Minute
Seconds = Format(((Minutes - Int(Minutes)) * 60), "0")
'Returns the Result of degree conversion
'(for example, 10.46 = 10~ 27 ' 36")
Convert_Degree = " " & Degrees & "~ " & Int(Minutes) & "' " _
& Seconds + Chr(34)
End With
End Function
To use this function, create a conversion formula, as in the following
example:
=Convert_Degree(10.46)This formula will return 10~ 27' 36" (that is, 10 degrees, 27 minutes, 36 seconds).
<degrees>~ <minutes>' <seconds>"as stated earlier.
Function Convert_Decimal(Degree_Deg As String) As Double
' Declare the variables to be double precision floating-point.
Dim degrees As Double
Dim minutes As Double
Dim seconds As Double
' Set degree to value before "~" of Argument Passed.
degrees = Val(Left(Degree_Deg, InStr(1, Degree_Deg, "~") - 1))
' Set minutes to the value between the "~" and the "'"
' of the text string for the variable Degree_Deg divided by
' 60. The Val function converts the text string to a number.
minutes = Val(Mid(Degree_Deg, InStr(1, Degree_Deg, "~") + 2, _
InStr(1, Degree_Deg, "'") - InStr(1, Degree_Deg, _
"~") - 2)) / 60
' Set seconds to the number to the right of "'" that is
' converted to a value and then divided by 3600.
seconds = Val(Mid(Degree_Deg, InStr(1, Degree_Deg, "'") + _
2, Len(Degree_Deg) - InStr(1, Degree_Deg, "'") - 2)) _
/ 3600
Convert_Decimal = degrees + minutes + seconds
End Function
To use this function, create a conversion formula, as in the following
example:
=Convert_Degree("10~ 27' 36""")
This formula will return 10.46 (that is, 10.46 degrees).
163435 VBA: Programming Resources for Visual Basic for Applications
Additional query words: 5.00a 5.00c 7.00a 97 XL97 XL7 XL5 XL
Keywords: kbdtacode kbhowto kbprogramming KB121944