View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Shawn Shawn is offline
external usenet poster
 
Posts: 271
Default Code Calculation Problem

I apologize in advance for re-posting this question. However, I haven't got
an answer to it yet and thought a fresh string might catch some "new" eyes.
I can't get the formula to calculate correctly. If I just put J1 in the
formula, it does fine. However, I don't want to put J1, I want to put var1.
This is vital to some significant programming I plan on doing, but have to
make it work on the small scale first. Please help!

Private Sub CommandButton1_Click()

Dim Ans1 As Range
Dim var1 As String
Dim WS As Worksheet

Set WS = Worksheets("Sheet1")
Set Ans1 = WS.Range("h2")
var1 = "J1"

Ans1.Value = Worksheets("sheet1").Evaluate("=SUMPRODUCT((A1:A10 ="" &
var1 & "")*(B1:B10=k1))")

End Sub


--
Thanks
Shawn