|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub 字典法()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("1")
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a1").Resize(1, c)
- For j = 1 To UBound(arr, 2)
- d(arr(1, j)) = j
- Next
- .UsedRange.Offset(1, 0).Clear
- End With
- With Worksheets("2")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a1").Resize(1, c)
- For j = 1 To UBound(arr, 2)
- If d.exists(arr(1, j)) Then
- .Cells(1, j).Resize(r, 1).Copy Worksheets("1").Cells(1, d(arr(1, j)))
- End If
- Next
- End With
- End Sub
复制代码 |
|