|
- Sub 计算1()
- Application.ScreenUpdating = False
- Dim tt As Double
- tt = Timer
- Dim rng1, rng2
- Dim Row1 As Long, Row2 As Long
- Dim Lat2 As Double, Lng2 As Double, Distance As Double, MinDistance As Double, CellID As String, CellName As String
- rng1 = Sheet1.Range("A1:D3000").Value
- rng2 = Sheet2.Range("A1:D6443").Value
- For Row1 = 2 To UBound(rng1)
- MinDistance = &H7FFFFFF
- For Row2 = 2 To UBound(rng2)
- If rng1(Row1, 3) <> rng2(Row2, 3) And rng1(Row1, 4) <> rng2(Row2, 4) Then
- Distance = GetDis(CDbl(rng1(Row1, 4)), CDbl(rng1(Row1, 3)), CDbl(rng2(Row2, 4)), CDbl(rng2(Row2, 3)))
- If Distance < MinDistance Then
- Lat2 = rng2(Row2, 4)
- Lng2 = rng2(Row2, 3)
- MinDistance = Distance
- CellID = rng2(Row2, 1)
- CellName = rng2(Row2, 2)
- LatDiff = rng1(Row1, 4) - rng2(Row2, 4)
- LngDiff = rng1(Row1, 3) - rng2(Row2, 3)
- End If
- End If
- Next
- Sheet1.Cells(Row1, 5) = Lng2
- Sheet1.Cells(Row1, 6) = Lat2
- Sheet1.Cells(Row1, 7) = MinDistance
- Sheet1.Cells(Row1, 8) = CellID
- Sheet1.Cells(Row1, 9) = CellName
- Application.StatusBar = "已处理到:" & Row1 & "行,当前进度:" & CInt(Row1 * 100 / UBound(rng1)) & "%,用时:" & CInt(Timer - tt) & "秒"
- DoEvents
- Next
- Application.ScreenUpdating = True
- MsgBox Format(Timer - tt, "0.00") & "second", 64, "运行时长: "
-
- End Sub
复制代码 试验了一下这个代码20多行只需要1秒,3000行需要2分钟左右 |
|