- Sub test1()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("标准")
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a1").Resize(2, c)
- For j = 2 To UBound(arr, 2)
- d(arr(1, j)) = arr(2, j)
- Next
- End With
- With Worksheets("报表")
- r = .Cells(.Rows.Count, 1).End(xlUp).Row
- c = .Cells(1, .Columns.Count).End(xlToLeft).Column
- arr = .Range("a1").Resize(r, c)
- End With
- ReDim brr(1 To (UBound(arr) - 1) * (UBound(arr, 2) - 6), 1 To 7)
- m = 0
- For i = 2 To UBound(arr)
- For j = 6 To UBound(arr, 2) - 1
- If Len(arr(i, j)) <> 0 Then
- m = m + 1
- For k = 1 To 3
- brr(m, k) = arr(i, k)
- Next
- brr(m, 4) = arr(1, j)
- brr(m, 5) = arr(i, j)
- If d.exists(arr(1, j)) Then
- brr(m, 6) = d(arr(1, j))
- brr(m, 7) = brr(m, 5) * brr(m, 6)
- End If
- End If
- Next
- Next
- With Worksheets("转换(1)")
- .UsedRange.Offset(1, 0).Delete
- .Range("a2").Resize(m, UBound(brr, 2)) = brr
- End With
- End Sub
复制代码 |