We help IT Professionals succeed at work.
Get Started

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

104 Views
Last Modified: 2020-02-07
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

Open in new window

Capture.PNG
Comment
Watch Question
Analyst Assistant
CERTIFIED EXPERT
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE