|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
实例11:
- Sub realGame()
- Dim d, arr(), i%, j%, k%, originArr
- ReDim arr(1 To 5, 1 To 1)
- k = 0
- Set d = CreateObject("Scripting.Dictionary")
- originArr = Range("a1").CurrentRegion
- arr(1, 1) = "性别"
- arr(2, 1) = "姓名"
- For j = 1 To UBound(originArr, 2) Step 3
- '每月工资标题
- arr(Int(j / 3) + 3, 1) = originArr(1, j + 2)
- For i = 2 To UBound(originArr)
- If originArr(i, j) = "" Then Exit For
- If Not d.exists(originArr(i, j) & "|" & originArr(i, j + 1)) Then
- k = k + 1 '不重复员工计数
- If k + 1 > UBound(arr, 2) Then 'arr当前容量不支持k行数据+1标题行
- ReDim Preserve arr(1 To 5, 1 To UBound(arr, 2) + 10)
- End If
- d(originArr(i, j) & "|" & originArr(i, j + 1)) = k + 1 '每个不重复姓名映射自己所占用的列标
- '在该员工自己占用列的一二行输入自己的性别、姓名
- arr(1, k + 1) = originArr(i, j)
- arr(2, k + 1) = originArr(i, j + 1)
- End If
- arr(Int(j / 3) + 3, d(originArr(i, j) & "|" & originArr(i, j + 1))) = originArr(i, j + 2)
- Next
- Next
- [j:z].ClearContents
- [j12].Resize(k + 1, 5) = Application.Transpose(arr)
- End Sub
复制代码 |
|