|
目前我这段代码,单行比对5万多行,计算时间大部分都在9秒左右,有点慢。
请教高手,还有提速的可能么?
Option Explicit
Sub test()
Dim i&, n&, r&, Arr, arr1, t
t = Timer
Application.ScreenUpdating = False
ActiveSheet.Range("$A$1:$H$100000").AutoFilter Field:=8
r = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
Sheets("Sheet1").Range("H2:H" & r).ClearContents
Arr = Sheets("Sheet1").Range("e2:f" & r)
ReDim arr1(1 To UBound(Arr), 1 To 1)
r = r - 1
For i = 1 To r
n = i
arr1(n, 1) = jl(Range("J1"), Range("K1"), Arr(i, 1), Arr(i, 2))
If arr1(n, 1) > Range("M1") Then
arr1(n, 1) = ""
Else
[H2].Resize(UBound(Arr), 1) = arr1
End If
Next i
ActiveSheet.Range("$A$1:$H$100000").AutoFilter Field:=8, Criteria1:="<>"
Application.ScreenUpdating = True
'MsgBox "总运行时间为" & Timer - t
End Sub
Function jl(x1, y1, x2, y2)
jl = 6378137 * 2 * Application.Asin(Sqr(Application.SumSq(Sin((Application.Radians(y1) - Application.Radians(y2)) / 2)) + Cos(Application.Radians(y1)) * Cos(Application.Radians(y2)) * Application.SumSq(Sin((Application.Radians(x1) - Application.Radians(x2)) / 2))))
End Function
|
|