How do I assign "Apple" to a cell reference in this evaluate code?

L

lhkittle

Sub Cnt() correctly returns 16.
Sub Cnt1() either Msgbox line returns 0

Option Explicit

Sub Cnt()
MsgBox Evaluate("SUMIF(D2:D7,""Apple"",E2:E7)")
End Sub

Sub Cnt1()
Dim i As Variant
i = Range("F1").Value
'MsgBox Evaluate("SUMIF(D2:D7,""i"",E2:E7)")
MsgBox Evaluate("SUMIF(D2:D7,i,E2:E7)")
End Sub

Thanks,
Regards,
Howard
 
P

plinius

Il 28/11/2012 09:31, (e-mail address removed) ha scritto:
Sub Cnt() correctly returns 16.
Sub Cnt1() either Msgbox line returns 0

Option Explicit

Sub Cnt()
MsgBox Evaluate("SUMIF(D2:D7,""Apple"",E2:E7)")
End Sub

Sub Cnt1()
Dim i As Variant
i = Range("F1").Value
'MsgBox Evaluate("SUMIF(D2:D7,""i"",E2:E7)")
MsgBox Evaluate("SUMIF(D2:D7,i,E2:E7)")
End Sub

Thanks,
Regards,
Howard

You can use directly F1, or avoid "Evaluate"

Sub Cnt1()
MsgBox Evaluate("SUMIF(D2:D7,F1,E2:E7)")
End Sub


Sub Cnt1()
Dim i As Variant
i = Range("F1").Value
MsgBox Application.SumIf([D2:D7], i, [E2:E7])
End Sub


Hi,
E.
 
L

lhkittle

Il 28/11/2012 09:31, (e-mail address removed) ha scritto:
Sub Cnt() correctly returns 16.
Sub Cnt1() either Msgbox line returns 0

Option Explicit

Sub Cnt()
MsgBox Evaluate("SUMIF(D2:D7,""Apple"",E2:E7)")
End Sub

Sub Cnt1()
Dim i As Variant
i = Range("F1").Value
'MsgBox Evaluate("SUMIF(D2:D7,""i"",E2:E7)")
MsgBox Evaluate("SUMIF(D2:D7,i,E2:E7)")



You can use directly F1, or avoid "Evaluate"



Sub Cnt1()

MsgBox Evaluate("SUMIF(D2:D7,F1,E2:E7)")

End Sub





Sub Cnt1()

Dim i As Variant

i = Range("F1").Value

MsgBox Application.SumIf([D2:D7], i, [E2:E7])

End Sub





Hi,

E.

Spot On!!

Thanks plinius.
 

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

Top