|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub test()
Dim ar, br
Dim i&, j&
ar = Sheet1.Range("A1").CurrentRegion
br = Sheet2.Range("A1").CurrentRegion
ReDim cr(1 To 1000, 1 To 3)
Set Dic = CreateObject("Scripting.Dictionary")
For i = 2 To UBound(br)
Dic(br(i, 1)) = ""
Next
For i = 2 To UBound(ar)
If Dic.Exists(ar(i, 1)) Then
For j = 2 To UBound(br, 2)
k = k + 1
cr(k, 1) = ar(i, 1)
cr(k, 2) = Left(br(1, j), Len(br(1, j)) - 2)
cr(k, 3) = ar(i, 2) * Val(br(i, j))
Next
Else
k = k + 1
cr(k, 1) = ar(i, 1)
cr(k, 2) = "总成绩"
cr(k, 3) = ar(i, 2)
End If
Next
With Sheet3
.Cells.Clear
.Range("A1").Resize(, UBound(cr, 2)) = Split("班级 科目 成绩")
.Range("A2").Resize(k, UBound(cr, 2)) = cr
End With
Set Dic = Nothing
End Sub |
评分
-
1
查看全部评分
-
|