|
▼NANAMI さん:
>
>for nextとsumifsを使って作りたいのです
Worksheets("練習15")では、ループ必要ないでしょう。
Sub test()
Dim r1 As Range
Dim r2 As Range
Dim i As Long
Dim j As Long
Set r1 = Worksheets("練習15").Range("A1").CurrentRegion
Set r2 = Worksheets("練習15_回答").Range("A1").CurrentRegion
For i = 2 To r2.Rows.Count
For j = 2 To r2.Columns.Count
r2(i, j).Value = WorksheetFunction.SumIfs(r1.Columns(3), _
r1.Columns(1), r2(1, j).Value, r1.Columns(2), r2(i, 1).Value)
Next
Next
End Sub
数式を一括で挿入して、それを値に変換すると
ープなしでできます。
Sub test2()
Dim r1 As Range
Dim r2 As Range
Dim f As String
Set r1 = Worksheets("練習15").Range("A1").CurrentRegion
Set r2 = Worksheets("練習15_回答").Range("A1").CurrentRegion
Set r2 = Intersect(r2, r2.Offset(1, 1))
f = "=sumifs(" _
& r1.Columns(3).Address(-1, -1, , -1) & "," _
& r1.Columns(1).Address(-1, -1, , -1) & "," _
& r2(0, 1).Address(-1, 0) & "," _
& r1.Columns(2).Address(-1, -1, , -1) & "," _
& r2(1, 0).Address(0, -1) & ")"
r2.Formula = f
r2.Value = r2.Value
End Sub
|
|