1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| Function convToDMS(dd, isLng)
Dim Direction, absDd, deg, frac, min, sec
dd = CDbl(Replace(dd, ".", ","))
If dd < 0 Then
If isLng Then Direction = "W" Else Direction = "S"
Else
If isLng Then Direction = "E" Else Direction = "N"
End If
absDd = Abs(CDbl(dd))
deg = Int(absDd)
frac = absDd - deg
min = Abs(Int(frac * 60))
sec = frac * 3600 - min * 60
sec = Abs(Int(sec * 1000) / 1000)
convToDMS = CStr(deg) + "°" + CStr(min) + "'" + _
Replace(Format(sec, "00''.000"), ",", ".") + " " + Direction
End Function
Sub Conversion()
Dim Rng As Range
Dim Ws As Worksheet
Dim WorkRng As Range
Dim num1, num2, num3
Set Ws = Worksheets("Country")
For Each Rng In Ws.Range("Coords").Rows
Rng.Cells(1, 3).Value = convToDMS(Rng.Cells(1, 1).Value, False)
Rng.Cells(1, 4).Value = convToDMS(Rng.Cells(1, 2).Value, True)
Next Rng
End Sub |
Partager