|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub test()
- Dim i&, arr, sth1 As Worksheet, sth2 As Worksheet, l&, zd As Object, j&, name$, names(), nums()
- Set zd = CreateObject("scripting.dictionary")
- Set sth1 = Worksheets(1)
- Set sth2 = Worksheets(2)
- sth2.Activate
- l = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
- For i = 2 To l
- k = Cells(i, 1)
- zd.Add k, Cells(i, 2)
- Next i
- sth1.Activate
- l = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
- For j = 2 To l
- name = Cells(j, 1)
- sth1.Cells(j, 3) = zd.Item(name)
- zd.Remove name
- Next j
- l = zd.Count - 1
- names = zd.keys()
- nums = zd.items()
- Range("k1:l1") = Array("姓名", "办公费")
- Range(Cells(2, "k"), Cells(2 + l, "k")) = WorksheetFunction.Transpose(names)
- Range(Cells(2, "l"), Cells(2 + l, "l")) = WorksheetFunction.Transpose(nums)
- End Sub
- 新手上路
复制代码 |
|