troubleshooting Question

Trying to write a SumProduct formula (using double negative method ) in VBA

Avatar of newparadigmz
newparadigmzFlag for United States of America asked on
VBAMicrosoft ExcelMicrosoft Office
4 Comments1 Solution111 ViewsLast Modified:
I'm trying to recreate this formula in VBA and getting a "Type mismatch" error. Able to do it via R1C1 and then .filldown, but explicitly trying to avoid that has it's super slow in the real data set.

Can't figure out what I'm doing wrong. I've used this method in simpler SumIf formulas before...

Sub WriteFormulas()
    Dim rQnty As Range, rName As Range, rDate As Range
    Dim vQnty As Variant, vName As Variant, vDate As Variant
    Dim j As Double, dValue As Double

    With ThisWorkbook.Worksheets(1)
        Set rQnty = .Range("A2:A10")
        Set rName = .Range("B2:B10")
        Set rDate = .Range("C2:C10")
    End With
    vQnty = rQnty.Value
    vName = rName.Value
    vDate = rDate.Value
    For j = 1 To UBound(vQnty)
        dValue = WorksheetFunction.SumProduct((rQnty), --(rName = vName(j, 1)), --(rDate = vDate(j, 1)))
    Next j
    'Range("D2").FormulaR1C1 = "=SUMPRODUCT(RC[-3]:R[8]C[-3],--(RC[-2]:R[8]C[-2]=""John""),--(RC[-1]:R[8]C[-1]=""Jan""))"
End Sub
NorieAnalyst Assistant
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros