|
本帖最后由 duquancai 于 2018-7-14 16:09 编辑
dancefly09 发表于 2018-7-13 12:38
非常感谢您,非常感谢。不过可能有点问题,我的描述不是特别清楚,我最后需要的是按照排序的结果,把单元 ... - Option Explicit
- Sub main()
- Dim n&, r&, i&, j&, crr(), q, g As Range, s$, Arr() As Range, pt As Date, kt As Date, js As Object
- Set g = Range("a:b").Find("*", , , , 1, 2): If g Is Nothing Then Exit Sub
- r = g.Row: If r < 2 Then Exit Sub
- kt = [e1].Value: crr = Range("a1:b" & r)
- For j = 1 To 2
- For i = 2 To r
- If Len(crr(i, j)) Then
- pt = CDate(crr(i, j))
- If pt < kt Then
- n = n + 1
- s = s & "," & "[" & "'" & pt & "'" & "," & n & "," & "'" & i & " " & j & "'" & "]"
- End If
- End If
- Next
- Next
- s = "[" & Mid(s, 2) & "]": If n > 0 Then ReDim Arr(1 To n)
- Set js = CreateObject("MSScriptControl.ScriptControl")
- js.Language = "JavaScript"
- js.eval ("a=" & s & ";a.sort(function(x,y){return (new Date(x[0])==new Date(y[0]))?(x[1]-y[1]):(new Date(x[0])-new Date(y[0]))});")
- For i = 0 To n - 1
- q = Split(js.eval("a[" & i & "][2]"))
- Set Arr(i + 1) = Cells(1 * q(0), 1 * q(1))
- MsgBox Arr(i + 1).Address(0, 0)
- Next
- MsgBox IIf(n > 0, "请检查对象数组Arr", "!!!")
- End Sub
复制代码 |
|