Evaluate using a variable - Help please
"Fredrik Wahlgren" wrote in message
...
"SA3214 @Eclipse.co.uk" <sa3214<No Spam wrote in message
...
I am having some difficulty substituting a variable (LastPRow) in place
of
the Number 20 in the code below.
I assumed that if I substituted " & LastPRow & " for 20 it would
work
... but it doesn't.
It returns Error 13, Type Mismatch
TIA for any help you can provide
vba code ..........
With Sheets("Payments")
LastPRow = .Cells(65536, 1).End(xlUp).Row
TextBox11 = Format(Evaluate("SUM(IF(((A2:A20)=""" &
ComboBox2.Value & """)*((B2:B20)=" & CDbl(TextBox4.Text) & "),D1:D10))"),
"#,###.00")
End With
Why do you use CDbl(TextBox4.Text) ? It is already text.If you want to
replace 20 with LastPRow do this
TextBox11 = Format(Evaluate("SUM(IF(((A2:A" & Cstr(LastPRow) & ")=""" &
ComboBox2.Value & """)*((B2:B" & Cstr(LastPRow) & ")=" &
CDbl(TextBox4.Text) & "),D1:D10))"), "#,###.00")
/Fredrik
1) CDbl(TextBox4.Text) .... This was left over from previous attempts to
avoid the mismatch error I have removed the conversion and (as you implied)
it makes no difference.
2) However substituting " & Cstr(LastPRow) & " for 20 still gives me the
Mismatch error
There was also an error in my original post but I don't think it affects the
mismatch ... D10 should have been D20
|