|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- Set d = CreateObject("scripting.dictionary")
- a = Array("户主", "父亲", "母亲", "夫", "妻", "兄", "弟", "姐姐", "妹妹", "儿媳")
- For i = 0 To UBound(a)
- d(a(i)) = i * 10 ^ (-9)
- Next
- With Sheets("sheet1")
- r = .Cells(Rows.Count, 1).End(3).Row
- arr = .Range("a1:g" & r)
- For i = 2 To UBound(arr)
- If Not d.exists(arr(i, 5)) Then
- n = n + 1
- d(arr(i, 5)) = n
- End If
- If InStr(arr(i, 6), "子") Or InStr(arr(i, 6), "女") Then
- s = Mid(arr(i, 3), 7, 8) * 10 ^ (-8)
- Else
- If d.exists(arr(i, 6)) Then
- s = d(arr(i, 6))
- End If
- End If
- arr(i, 7) = d(arr(i, 5)) + s
- Next
- End With
- With Sheets("sheet2")
- .UsedRange.ClearContents
- .[a1].Resize(UBound(arr), 7) = arr
- .[a1].Resize(r, 8).Sort key1:=.Range("g1"), order1:=1, Header:=1
- .Range("g:g").Delete
- End With
- End Sub
复制代码
这个是在表2中进行排序的,但是遇到重名时需要再进一步判断 |
|