0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【ExcelVBA】緯度経度の表示変換(度分秒→10進、10進→度分秒)

Posted at

'############################################################
'#緯度経度の表示方法を変換する
'#
'# 引数1:str(度分秒もしくは10進数で書かれた緯度or経度)
'# 引数2:i(省略時0:小数第何位まで表示させるか。四捨五入)
'# 戻値:度分秒の場合は10進数表記、10進数の場合は度分秒表記に変換された結果
'# 想定:日本国内(緯度経度ともに正の場合)
'# 対応表記:「°」「′」「’」「'」「″」※日本語の「度分秒」には対応していない
'#
'############################################################
Function Conv経緯度(ByVal str As String, Optional ByVal i As Long)

Dim  As Long,  As Long,  As Double
If IsNumeric(str) = True Then
    '10進数→度分秒
     = Int(str)
     = Int((str - ) * 60)
     = Round(((str - ) * 60 - ) * 60, i)
    Conv経緯度 =  & "°" &  & "′" &  & "″"
Else
    '度分秒→10進数
    str = StrConv(str, vbNarrow)        '「’」(全角)と「'」(半角)混在対処で半角に
    str = Replace(str, "'", "′")       '「'」を「′」に統一
    
     = Split(str, "°")(0)
     = Split(Split(str, "′")(0), "°")(1)
     = Val(Split(str, "′")(1))
    Conv経緯度 =  +  / 60 +  / 3600
End If

End Function


Sub test()
Debug.Print Conv経緯度("35°41′9.564""", 3)
Debug.Print Conv経緯度(35.68599, 6)

 35.686
35°419.564
End Sub
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?