0

SUMPRODUCTと一緒に関数を使ってマクロを作ろうとしていSUMIFます。しかし、マクロを実行すると…</p>

実行時エラー 13.

このようなセルで同じ関数を作成しようとしました。

=SUMPRODUCT(SUMIF(B2:B3,K15:K18,L15:L18))

それはうまく機能するので、コンセプトが証明されていることを私は知っています.

Sub GrandTotal() 'Finds the last non-blank cell in a single row or column
    Dim lRow As Long
    Dim lCol As Long
    Dim GrandTotal As Variant
    Dim MyRg1 As Variant
    Dim MyRg2 As Variant
    Dim MyRg3 As Variant

    'Find the last non-blank cell in column A(1)
    lRow = Cells(Rows.Count, 1).End(xlUp).Row

    'Find the last non-blank cell in row 1
    lCol = Cells(1, Columns.Count).End(xlToLeft).Column

    MsgBox "Last Row: " & lRow & vbNewLine & _
           "Last Column: " & lCol

    'set range
    Set MyRg1 = Range("B2:B3")
    'set criteria
    Set MyRg2 = Range("$K$15:$K$18")
    'set sum range
    Set MyRg3 = Range("$L$15:$L$18")

    For Each cell In Range(Cells(lRow, 2), Cells(lRow, lCol))
        GrandTotal = WorksheetFunction.SumProduct(WorksheetFunction.SumIf(MyRg1, MyRg2, MyRg3))
        cell.Value = GrandTotal
    Next cell  
End Sub

VBAで関数を使用する方法をいくつかのガイドを見つけました。同じ原則に従いました。また、スタックで別の投稿を見ましたが、その方法を示していましたが、エラーが発生しました。

親切な魂が助けてくれることを願っています

4

4 に答える 4