Pages

[XL-2010] VBA - Evaluate sumproduct with external excel databse file as variable sujet

jeudi 30 janvier 2014




Hello,

I want to evaluate the sumproduct from an external database.

Here is the code I use and the issue I have:


Code:


Dim m As Integer
Dim Pathd As String
Pathd = Range("Database").Value 'Return the Path to access to the external file

'This formula with two criteria works perfectly and return the number of entry in the database that are linked to the criteria selected.
'And I have tested it with the three criteria I have to make sure that the error doesn't come from a data error in the database

m = Evaluate("=SUMPRODUCT(('" & Pathd & "'!Column1=A2)*('" & Pathd & "'!Column2=D2))")

'OR

m = Evaluate("=SUMPRODUCT(('" & Pathd & "'!Column1=A2)*('" & Pathd & "'!Column3=E2))")

'OR

m = Evaluate("=SUMPRODUCT(('" & Pathd & "'!Column2=D2)*('" & Pathd & "'!Column3=E2))")

'All these three formulas work fine.

'But when I put all three criteria together, I get a mismatch error type
m = Evaluate("=SUMPRODUCT(('" & Pathd & "'!Column1=A2)*('" & Pathd & "'!Column2=D2)*('" & Pathd & "'!Column3=E2))")


I guess it is a syntax issue but the () and "" seems ok.

Any idea?

Thank you in advance for your help.
Sebastien




Aucun commentaire:

Enregistrer un commentaire