Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 709
Default SUMPRODUCT statement only works sometimes

I'm writing a long program to analyze my lab's financial data.

I created a subprogram that I want to copy into the longer program. The
subprogram calculates an array of subtotals using the SUMPRODUCT command

total = ActiveSheet.Evaluate("SUMPRODUCT((" & myRng1.Address & _
"=""" & myVar1 & """)" & "*" & myRng2.Address & ")")

It works fine, but I need to port this into the long program.
I copy/pasted the subprogram into my main program, but it hangs up at this
command. I've used debug.print to confirm all the variables and ranges in the
SUMPRODUCT statement, and the active sheet is the same.

I'm stuck. What else could be causing this statement to hang up?
--
Richard
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default SUMPRODUCT statement only works sometimes

What are the addresses of myRng1 and myrng2?

What's in myVar1?

Do you have any non-numeric data in myrng2?

Do you have any errors in myRng1?

Just as an aside, I like to specify my ranges a little mo

Option Explicit
Sub testme()
Dim Total As Double
Dim myRng1 As Range
Dim myRng2 As Range
Dim myVar1 As String

With ActiveSheet
Set myRng1 = .Range("a1:a10")
Set myRng2 = .Range("b1:b10")
myVar1 = .Range("c1").Value
End With

Total = Application.Evaluate("SUMPRODUCT((" & myRng1.Address(external:=True) _
& "=""" & myVar1 & """)" & "*" & myRng2.Address(external:=True) & ")")

MsgBox Total
End Sub

Just in case myRng1 and myRng2 aren't on the activesheet.

(If you really meant to use the addresses no matter where the ranges were
located, then ignore this aside.)


Richard wrote:

I'm writing a long program to analyze my lab's financial data.

I created a subprogram that I want to copy into the longer program. The
subprogram calculates an array of subtotals using the SUMPRODUCT command

total = ActiveSheet.Evaluate("SUMPRODUCT((" & myRng1.Address & _
"=""" & myVar1 & """)" & "*" & myRng2.Address & ")")

It works fine, but I need to port this into the long program.
I copy/pasted the subprogram into my main program, but it hangs up at this
command. I've used debug.print to confirm all the variables and ranges in the
SUMPRODUCT statement, and the active sheet is the same.

I'm stuck. What else could be causing this statement to hang up?
--
Richard


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 709
Default SUMPRODUCT statement only works sometimes

Thanks Dave.
Turns out that I already used "total" for another part of the program, and
the data types were in conflict.

I guess I need to stay away from such general named variables.

--
Richard


"Dave Peterson" wrote:

What are the addresses of myRng1 and myrng2?

What's in myVar1?

Do you have any non-numeric data in myrng2?

Do you have any errors in myRng1?

Just as an aside, I like to specify my ranges a little mo

Option Explicit
Sub testme()
Dim Total As Double
Dim myRng1 As Range
Dim myRng2 As Range
Dim myVar1 As String

With ActiveSheet
Set myRng1 = .Range("a1:a10")
Set myRng2 = .Range("b1:b10")
myVar1 = .Range("c1").Value
End With

Total = Application.Evaluate("SUMPRODUCT((" & myRng1.Address(external:=True) _
& "=""" & myVar1 & """)" & "*" & myRng2.Address(external:=True) & ")")

MsgBox Total
End Sub

Just in case myRng1 and myRng2 aren't on the activesheet.

(If you really meant to use the addresses no matter where the ranges were
located, then ignore this aside.)


Richard wrote:

I'm writing a long program to analyze my lab's financial data.

I created a subprogram that I want to copy into the longer program. The
subprogram calculates an array of subtotals using the SUMPRODUCT command

total = ActiveSheet.Evaluate("SUMPRODUCT((" & myRng1.Address & _
"=""" & myVar1 & """)" & "*" & myRng2.Address & ")")

It works fine, but I need to port this into the long program.
I copy/pasted the subprogram into my main program, but it hangs up at this
command. I've used debug.print to confirm all the variables and ranges in the
SUMPRODUCT statement, and the active sheet is the same.

I'm stuck. What else could be causing this statement to hang up?
--
Richard


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sumproduct not works kashish Excel Worksheet Functions 1 May 1st 09 03:52 PM
Sumproduct not works kashish Excel Worksheet Functions 3 May 1st 09 01:57 PM
Countif works, Sumproduct doesn't Jennifer Excel Worksheet Functions 4 February 13th 07 06:07 AM
SUMPRODUCT Works Sometimes Why Mestrella31 Excel Discussion (Misc queries) 4 January 17th 05 07:13 PM
Statement works in one scenario, not in other Tod Excel Programming 1 April 20th 04 03:59 PM


All times are GMT +1. The time now is 08:12 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"