Macro - KML数据:东西经,南北纬同时存在,负值转正值

'KML文件中如何PickUp一条Line的数据,将其中东西经,南北纬同时存在的情况,负值全转为正值

Attribute VB_Name = "KMLDLPNCal"

'2015/04/16 ADD By  MAOUIZAYOI

Option Explicit

' Excute Interface.
Sub KMLDLPNCal()

    Dim conSht As Object       'conSht is named from console.
    Dim srcRng As Range
    Dim aimRng As Range
    
    Dim itemFilter, strFilter, strBuffer, strBlank As String
    Dim strAarry() As String
    
    Dim latiSum, logiSum, commaL As Integer, i As Variant
    
    Set conSht = ActiveSheet.UsedRange
    Set srcRng = conSht.Range("A1")
    Set aimRng = conSht.Range("A3")
    
    itemFilter = ","
    strFilter = ",0 "
    strBuffer = ""
    strAarry = Split(srcRng.Value, strFilter)
    
    latiSum = 180
    logiSum = 360
    commaL = 1
       
    For i = 0 To UBound(strAarry)
        If strAarry(i) = "" Then
            Exit For
       ElseIf strAarry(i) = " " Then
            Exit For ' Otherwise TODO someting.
        Else
            
            ' Pattern 4 List
            If CDbl(Left(strAarry(i), InStr(strAarry(i), itemFilter) - commaL)) < 0 Then
                
                If CDbl(Mid(strAarry(i), InStr(strAarry(i), itemFilter) + commaL)) < 0 Then
                    strBuffer = strBuffer & CStr(CDbl(Left(strAarry(i), InStr(strAarry(i), itemFilter) - commaL)) + logiSum) & itemFilter & CStr(CDbl(Mid(strAarry(i), InStr(strAarry(i), itemFilter) + commaL)) + latiSum)
                Else
                    strBuffer = strBuffer & CStr(CDbl(Left(strAarry(i), InStr(strAarry(i), itemFilter) - commaL)) + logiSum) & itemFilter & Mid(strAarry(i), InStr(strAarry(i), itemFilter) + commaL)
                End If
            ElseIf CDbl(Left(strAarry(i), InStr(strAarry(i), itemFilter) - commaL)) >= 0 Then
            
                If CDbl(Mid(strAarry(i), InStr(strAarry(i), itemFilter) + commaL)) < 0 Then
                    strBuffer = strBuffer & Left(strAarry(i), InStr(strAarry(i), itemFilter) - commaL) & itemFilter & CStr(CDbl(Mid(strAarry(i), InStr(strAarry(i), itemFilter) + commaL)) + latiSum)
                Else
                    strBuffer = strBuffer & strAarry(i)
                End If
            End If
            
            strBuffer = strBuffer & strFilter
        End If
    Next
    
    If strBuffer <> "" Then
        aimRng.Value = strBuffer
    End If
   

End Sub

PS:如果是把KML中数据拷到Excel 一单元格然后执行的话,切记把源单元格和目标单元格的格式都切换成String:文字列的那种。普通默认的格式,数据存到一定长度会被截断。(Excel 2003 以上版本每个单元格大约存32000左右字节,自己注意好)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值