Sie sind auf Seite 1von 2

http://support.microsoft.

com/kb/213449/es
Convertir los grados decimales a grados/minutos/segundos
El siguiente ejemplo de Microsoft Visual Basic para Aplicaciones
funcin personalizada de acepta un ngulo con formato de un
valor decimal y lo convierte en un valor de texto que se muestra
en grados, minutos y segundos.
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
Para utilizar esta funcin, cree una frmula de conversin, como en
el ejemplo siguiente:
1. Inicie Excel y presione ALT+F11 para iniciar el editor de Visual
Basic.
2. En el men Insertar, haga clic en Mdulo.
3. Introduzca el cdigo de ejemplo para la funcin personalizada
Convert_Degree que se describe anteriormente en la hoja de
mdulo.
4. Presione ALT+F11 para volver a excel.
5. En la celda A1 escriba 10.46.
6. En la celda A2, escriba la frmula siguiente:
=Convert_Degree(a1)
La frmula devuelve 10 27'36 "
Conversin de grados, minutos y segundos a grados decimales
El siguiente ejemplo de Microsoft Visual Basic para Aplicaciones funcin
personalizada de acepta una cadena de texto de grados, minutos y segundos

http://support.microsoft.com/kb/213449/es
con el mismo formato exacto que devuelve la funcin Convert_Degree (por
ejemplo, 10 27' 36 ") y lo convierte en un ngulo como un valor
decimal. Esto es exactamente el inverso de la funcin personalizada
Convert_Degree.
Advertencia: esta funcin personalizada se produce un error si el argumento
Degree_Deg no est en el siguiente formato
<degrees> <minutes> ' <seconds> "
incluso si el valor de segundos es 0.
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
Para utilizar esta funcin, cree una frmula de conversin, como en el ejemplo
siguiente:
1. Inicie Excel y presione ALT+F11 para iniciar el Editor de Visual Basic.
2. En el men Insertar, haga clic en Mdulo.
3. Introduzca el cdigo de ejemplo para la funcin personalizada
Convert_Decimal que se describe anteriormente en la hoja de mdulo.
4. Presione ALT+F11 para volver a excel.
5. En la celda A1 escriba la frmula siguiente:
= Convert_Decimal("10 27' 36""")
Nota: se le pide que escriba tres signos de comillas ("" ") al final del
argumento de esta frmula para equilibrar el signo de comillas para los
segundos y el signo de comillas para la cadena de texto. Una referencia
de celda no requerir una comilla.
6. La frmula devuelve 10.46

Das könnte Ihnen auch gefallen