|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub test0()
- Dim ar, br, cr(), Dict As Object
- Dim i As Long, j As Long, k As Long, p As Long
- ar = Sheet1.Range("A1").CurrentRegion
- br = Sheet2.Range("A1").CurrentRegion
- ReDim cr(1 To UBound(ar) * (UBound(br, 2) - 1), 1 To 3)
- Set Dict = CreateObject("Scripting.Dictionary")
- For i = 2 To UBound(br)
- Dict.Add br(i, 1), i
- Next
- For i = 2 To UBound(ar)
- If Dict.Exists(ar(i, 1)) Then
- p = Dict(ar(i, 1))
- For j = 2 To UBound(br, 2)
- k = k + 1
- cr(k, 1) = ar(i, 1)
- cr(k, 2) = Replace(br(1, j), "占比", "")
- cr(k, 3) = ar(i, 2) * Val(br(p, j))
- Next
- Else
- k = k + 1
- cr(k, 1) = ar(i, 1)
- cr(k, 2) = ar(1, 2)
- cr(k, 3) = ar(i, 2)
- End If
- Next
- With Sheet3.Range("A1")
- .CurrentRegion.ClearContents
- .Resize(, UBound(cr, 2)) = Split("班级 科目 成绩")
- .Offset(1).Resize(k, UBound(cr, 2)) = cr
- End With
- Set Dict = Nothing
- Beep
- End Sub
复制代码 |
|