|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 duquancai 于 2018-7-23 22:50 编辑
- Sub mySort()
- Dim js As Object, s$, sr$, f$
- a = Sheet1.[A1].CurrentRegion.Value
- Set js = CreateObject("MSScriptControl.ScriptControl")
- js.Language = "JavaScript"
- For i = 2 To UBound(a)
- For j = 1 To UBound(a, 2)
- If j = 1 Then s = "'" & a(i, j) & "'" Else: s = s & "," & "'" & a(i, j) & "'"
- Next
- sr = sr & "," & "[" & s & "]": s = Empty
- Next
- sr = "[" & Mid(sr, 2) & "]"
- f = "function(x,y){i=r.exec(x[2]);j=r.exec(y[2]);return (i[1]==j[1])?((i[2]==j[2])?(o[i[3]]-o[j[3]]):(i[2]-j[2])):(i[1].localeCompare(j[1]))}"
- js.eval ("r=/([A-Z]+)\D*(\d+)[^东南西北]*([东南西北])/;o={'东':4,'西':3,'南':2,'北':1};a=" & sr & ";a.sort(" & f & ")")
- For i = 2 To UBound(a)
- For j = 1 To UBound(a, 2)
- a(i, j) = js.eval("a[" & i - 2 & "][" & j - 1 & "]")
- Next
- Next
- Sheet2.Cells.Clear
- Sheet2.Range("a1").Resize(UBound(a), UBound(a, 2)) = a
- End Sub
复制代码 |
评分
-
2
查看全部评分
-
|