|
我是小白,我一般都是简单粗暴的方式,直接弄7个字典,简单明了
速度也不比你们大神的差
- Sub lizhipei78()
- Dim i&, Myr1&, Myr2&, Arr, Brr
- Dim Dic1, Dic2, Dic3, Dic4, Dic5, Dic6, Dic7, Dic8, k, t
- T1 = Timer
- Sheet2.Cells.ClearContents
- Set Dic1 = CreateObject("Scripting.Dictionary") '姓名
- Set Dic2 = CreateObject("Scripting.Dictionary") '编码
- Set Dic3 = CreateObject("Scripting.Dictionary") '家庭住址
- Set Dic4 = CreateObject("Scripting.Dictionary") '性别
- Set Dic5 = CreateObject("Scripting.Dictionary") '出生日期
- Set Dic6 = CreateObject("Scripting.Dictionary") '人员类别
- Set Dic7 = CreateObject("Scripting.Dictionary") '婚姻状态
- Myr1 = Sheet1.[A65536].End(xlUp).Row
- Arr = Sheet1.Range("A1:G" & Myr1)
- For i = 2 To UBound(Arr)
- Dic1(Arr(i, 3)) = Dic1(Arr(i, 3)) + 1 '统计姓名的重复次数
- Dic2(Arr(i, 3)) = Arr(i, 1) '编码
- Dic3(Arr(i, 3)) = Arr(i, 2) '家庭住址
- Dic4(Arr(i, 3)) = Arr(i, 4) '性别
- Dic5(Arr(i, 3)) = Arr(i, 5) '出生日期
- Dic6(Arr(i, 3)) = Arr(i, 6) '人员类别
- Dic7(Arr(i, 3)) = Arr(i, 7) '婚姻状态
- Next i
- k = Dic1.keys
- t = Dic1.items
- Sheet2.Activate
- [A2].Resize(Dic1.Count, 1) = Application.Transpose(k) '姓名
- [B2].Resize(Dic1.Count, 1) = Application.Transpose(t) '重复次数
- [A1].Resize(1, 8) = Array("姓名", "重复次数", "编码", "家庭住址", "性别", "出生日期", "人员类别", "婚姻状态") '写标题
- Myr2 = Sheet2.[A65536].End(xlUp).Row
- Brr = Sheet2.Range("A1:H" & Myr2)
- For i = 2 To UBound(Brr)
- Brr(i, 3) = Dic2(Brr(i, 1)) '编码
- Brr(i, 4) = Dic3(Brr(i, 1)) '家庭住址
- Brr(i, 5) = Dic4(Brr(i, 1)) '性别
- Brr(i, 6) = Dic5(Brr(i, 1)) '出生日期
- Brr(i, 7) = Dic6(Brr(i, 1)) '人员类别
- Brr(i, 8) = Dic7(Brr(i, 1)) '婚姻状态
- Next i
- [A1].Resize(Myr2, 8) = Brr
- MsgBox Format(Timer - T1, "0.00") & "秒"
- End Sub
复制代码
|
|