Excel XP VBA Array formula

  • Thread starter Thread starter SMS - John Howard
  • Start date Start date
S

SMS - John Howard

The first two sub procedures below work OK

The third one however, produces a Type Mismatch error.

Do VBA Array formulas not accept variable arguments or am I miss-keying
something?

All help gratefully accepted. :-)

Dim rep As String
Dim pco As String

Sub addpco()

Range("K1") = "005522"
Range("L1") = "PRI"

rep = "005522"
pco = "PRI"

TotalPRI = [Sum((A2:A14=K1)*(D2:D14=L1)*(G2:G14))]
MsgBox TotalPRI

TotalPRI = [Sum((A2:A14="005522")*(D2:D14="PRI")*(G2:G14))]
MsgBox TotalPRI

TotalPRI = [Sum((A2:A14=rep)*(D2:D14=pco)*(G2:G14))]
MsgBox TotalPRI

End Sub


Thanks in Anticipation

John Howard
Sydney, Australia
 
[ ] notation for the Evaluate method requires a string between the [] rather
than a mixture of string and VBA variables.
If you want to construct the string using VBA you should use
Application.Evaluate or worksheet.Evaluate rather than []

Also you need to be careful when using Application.Evaluate with unqualified
range references like D2:D14 because they refer to whatever happens to be
the active worksheet at evaluation time: safer to use worksheet.evaluate or
qualified range references.

Charles
______________________
Decision Models
FastExcel 2.1 now available
www.DecisionModels.com
 
Thanks Charles.
I will experiment around your suggestions.
Charles Williams said:
[ ] notation for the Evaluate method requires a string between the [] rather
than a mixture of string and VBA variables.
If you want to construct the string using VBA you should use
Application.Evaluate or worksheet.Evaluate rather than []

Also you need to be careful when using Application.Evaluate with unqualified
range references like D2:D14 because they refer to whatever happens to be
the active worksheet at evaluation time: safer to use worksheet.evaluate or
qualified range references.

Charles
______________________
Decision Models
FastExcel 2.1 now available
www.DecisionModels.com

SMS - John Howard said:
The first two sub procedures below work OK

The third one however, produces a Type Mismatch error.

Do VBA Array formulas not accept variable arguments or am I miss-keying
something?

All help gratefully accepted. :-)

Dim rep As String
Dim pco As String

Sub addpco()

Range("K1") = "005522"
Range("L1") = "PRI"

rep = "005522"
pco = "PRI"

TotalPRI = [Sum((A2:A14=K1)*(D2:D14=L1)*(G2:G14))]
MsgBox TotalPRI

TotalPRI = [Sum((A2:A14="005522")*(D2:D14="PRI")*(G2:G14))]
MsgBox TotalPRI

TotalPRI = [Sum((A2:A14=rep)*(D2:D14=pco)*(G2:G14))]
MsgBox TotalPRI

End Sub


Thanks in Anticipation

John Howard
Sydney, Australia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Advanced Filter with Non-Contiguous Ranges 2
vba for countif 3
VB Script Help in Excel 2007 1
Naming non-contigent cells with vba 5
Array Formula 2
Formula Macro 6
copying an array formula 2
Array Formula 11

Back
Top