Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,388
Default SumProduct in VBA

Hi,
XL2003
I have the following Code:

Do Until Sheets("Sheet2").Cells(A, 4) = ""

B = Sheets("Sheet2").Cells(A, 4)

Sheets("Sheet2").Cells(A, 6) =
Evaluate("=SUMPRODUCT(--(Sheet1!C3:C100 = B) * (Sheet1!E3:E100))")

A = A + 1

Loop

In the Evaluate("Sumproduct... line, B is a variable, but it's not being read.
Can I use a variable in the above line?
Thanks in advance.
Dave.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default SumProduct in VBA

two things:

1. make B a string variable
2. splice it into the formula:
................" & B & "..................
--
Gary''s Student - gsnu200904


"Dave" wrote:

Hi,
XL2003
I have the following Code:

Do Until Sheets("Sheet2").Cells(A, 4) = ""

B = Sheets("Sheet2").Cells(A, 4)

Sheets("Sheet2").Cells(A, 6) =
Evaluate("=SUMPRODUCT(--(Sheet1!C3:C100 = B) * (Sheet1!E3:E100))")

A = A + 1

Loop

In the Evaluate("Sumproduct... line, B is a variable, but it's not being read.
Can I use a variable in the above line?
Thanks in advance.
Dave.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default SumProduct in VBA


Evaluate("=SUMPRODUCT(--(Sheet1!C3:C100 = " & B & ") * (Sheet1!E3:E100))")

Should work.

"Dave" wrote:

Hi,
XL2003
I have the following Code:

Do Until Sheets("Sheet2").Cells(A, 4) = ""

B = Sheets("Sheet2").Cells(A, 4)

Sheets("Sheet2").Cells(A, 6) =
Evaluate("=SUMPRODUCT(--(Sheet1!C3:C100 = B) * (Sheet1!E3:E100))")

A = A + 1

Loop

In the Evaluate("Sumproduct... line, B is a variable, but it's not being read.
Can I use a variable in the above line?
Thanks in advance.
Dave.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default SumProduct in VBA

Me again, if B is text rather than a number, you'll need:

Evaluate("=SUMPRODUCT(--(Sheet1!C3:C100 = """ & B & """) * (Sheet1!E3:E100))")

"Dave" wrote:

Hi,
XL2003
I have the following Code:

Do Until Sheets("Sheet2").Cells(A, 4) = ""

B = Sheets("Sheet2").Cells(A, 4)

Sheets("Sheet2").Cells(A, 6) =
Evaluate("=SUMPRODUCT(--(Sheet1!C3:C100 = B) * (Sheet1!E3:E100))")

A = A + 1

Loop

In the Evaluate("Sumproduct... line, B is a variable, but it's not being read.
Can I use a variable in the above line?
Thanks in advance.
Dave.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,388
Default SumProduct in VBA

Hi Sam,
B is text, and your code works. Thanks a lot!
Can you tell me why we need 3 lots of double quotes?
Thanks to all the others that responded.
Regards - Dave.

"Sam Wilson" wrote:

Me again, if B is text rather than a number, you'll need:

Evaluate("=SUMPRODUCT(--(Sheet1!C3:C100 = """ & B & """) * (Sheet1!E3:E100))")

"Dave" wrote:

Hi,
XL2003
I have the following Code:

Do Until Sheets("Sheet2").Cells(A, 4) = ""

B = Sheets("Sheet2").Cells(A, 4)

Sheets("Sheet2").Cells(A, 6) =
Evaluate("=SUMPRODUCT(--(Sheet1!C3:C100 = B) * (Sheet1!E3:E100))")

A = A + 1

Loop

In the Evaluate("Sumproduct... line, B is a variable, but it's not being read.
Can I use a variable in the above line?
Thanks in advance.
Dave.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default SumProduct in VBA

Dave, it looks strange but VBA interprets a double-double quote in a string
as a single double quote or CHR(34)

If this post helps click Yes
---------------
Jacob Skaria


"Dave" wrote:

Hi Sam,
B is text, and your code works. Thanks a lot!
Can you tell me why we need 3 lots of double quotes?
Thanks to all the others that responded.
Regards - Dave.

"Sam Wilson" wrote:

Me again, if B is text rather than a number, you'll need:

Evaluate("=SUMPRODUCT(--(Sheet1!C3:C100 = """ & B & """) * (Sheet1!E3:E100))")

"Dave" wrote:

Hi,
XL2003
I have the following Code:

Do Until Sheets("Sheet2").Cells(A, 4) = ""

B = Sheets("Sheet2").Cells(A, 4)

Sheets("Sheet2").Cells(A, 6) =
Evaluate("=SUMPRODUCT(--(Sheet1!C3:C100 = B) * (Sheet1!E3:E100))")

A = A + 1

Loop

In the Evaluate("Sumproduct... line, B is a variable, but it's not being read.
Can I use a variable in the above line?
Thanks in advance.
Dave.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default SumProduct in VBA

To avoid that confusion you can try out the below..

(Should have bee in one line. Just to show the individual pieces)

"=SUMPRODUCT(--(Sheet1!C3:C100=" &
Chr(34) & B & Chr(34) &
")*(Sheet1!E3:E100))"

If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

Dave, it looks strange but VBA interprets a double-double quote in a string
as a single double quote or CHR(34)

If this post helps click Yes
---------------
Jacob Skaria


"Dave" wrote:

Hi Sam,
B is text, and your code works. Thanks a lot!
Can you tell me why we need 3 lots of double quotes?
Thanks to all the others that responded.
Regards - Dave.

"Sam Wilson" wrote:

Me again, if B is text rather than a number, you'll need:

Evaluate("=SUMPRODUCT(--(Sheet1!C3:C100 = """ & B & """) * (Sheet1!E3:E100))")

"Dave" wrote:

Hi,
XL2003
I have the following Code:

Do Until Sheets("Sheet2").Cells(A, 4) = ""

B = Sheets("Sheet2").Cells(A, 4)

Sheets("Sheet2").Cells(A, 6) =
Evaluate("=SUMPRODUCT(--(Sheet1!C3:C100 = B) * (Sheet1!E3:E100))")

A = A + 1

Loop

In the Evaluate("Sumproduct... line, B is a variable, but it's not being read.
Can I use a variable in the above line?
Thanks in advance.
Dave.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,388
Default SumProduct in VBA

Hi Jacob,
Thanks for your help and clarification.
Dave.

"Jacob Skaria" wrote:

To avoid that confusion you can try out the below..

(Should have bee in one line. Just to show the individual pieces)

"=SUMPRODUCT(--(Sheet1!C3:C100=" &
Chr(34) & B & Chr(34) &
")*(Sheet1!E3:E100))"

If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

Dave, it looks strange but VBA interprets a double-double quote in a string
as a single double quote or CHR(34)

If this post helps click Yes
---------------
Jacob Skaria


"Dave" wrote:

Hi Sam,
B is text, and your code works. Thanks a lot!
Can you tell me why we need 3 lots of double quotes?
Thanks to all the others that responded.
Regards - Dave.

"Sam Wilson" wrote:

Me again, if B is text rather than a number, you'll need:

Evaluate("=SUMPRODUCT(--(Sheet1!C3:C100 = """ & B & """) * (Sheet1!E3:E100))")

"Dave" wrote:

Hi,
XL2003
I have the following Code:

Do Until Sheets("Sheet2").Cells(A, 4) = ""

B = Sheets("Sheet2").Cells(A, 4)

Sheets("Sheet2").Cells(A, 6) =
Evaluate("=SUMPRODUCT(--(Sheet1!C3:C100 = B) * (Sheet1!E3:E100))")

A = A + 1

Loop

In the Evaluate("Sumproduct... line, B is a variable, but it's not being read.
Can I use a variable in the above line?
Thanks in advance.
Dave.

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default SumProduct in VBA

Try

Sheets("Sheet2").Cells(a, 6) = _
Evaluate("=SUMPRODUCT(--(Sheet1!C3:C100=" & B & ")*(Sheet1!E3:E100))")

If this post helps click Yes
---------------
Jacob Skaria


"Dave" wrote:

Hi,
XL2003
I have the following Code:

Do Until Sheets("Sheet2").Cells(A, 4) = ""

B = Sheets("Sheet2").Cells(A, 4)

Sheets("Sheet2").Cells(A, 6) =
Evaluate("=SUMPRODUCT(--(Sheet1!C3:C100 = B) * (Sheet1!E3:E100))")

A = A + 1

Loop

In the Evaluate("Sumproduct... line, B is a variable, but it's not being read.
Can I use a variable in the above line?
Thanks in advance.
Dave.

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default SumProduct in VBA

in yuor code 'b' is just a letter

either

Sheets("Sheet2").Cells(A, 6).FormulaR1C1 = _
"=SUMPRODUCT((Sheet1!R3C3:R100C3 = RC4) * (Sheet1!R3C5:R100C5))"
then
Sheets("Sheet2").Cells(A, 6).Value = Sheets("Sheet2").Cells(A, 6).Value


or this (untried)


With Worksheets("Sheet1")
Sheets("Sheet2").Cells(A, 6).Value =
WorksheetFunction.SumProduct(.Range("C3:C100") = B) * (.Range("E3:E100"))
End With

or Gary's idea


Sheets("Sheet2").Cells(A, 6) = worksheetFunction.SUMPRODUCT((Sheet1!C3:C100
= B) * (Sheet1!E3:E100))")





"Dave" wrote:

Hi,
XL2003
I have the following Code:

Do Until Sheets("Sheet2").Cells(A, 4) = ""

B = Sheets("Sheet2").Cells(A, 4)

Sheets("Sheet2").Cells(A, 6) =
Evaluate("=SUMPRODUCT(--(Sheet1!C3:C100 = B) * (Sheet1!E3:E100))")

A = A + 1

Loop

In the Evaluate("Sumproduct... line, B is a variable, but it's not being read.
Can I use a variable in the above line?
Thanks in advance.
Dave.



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 with Condition OR Sumproduct with ADDRESS function - HE gholly Excel Discussion (Misc queries) 2 September 28th 09 05:07 PM
SumProduct judith Excel Worksheet Functions 3 June 22nd 09 09:12 PM
sumproduct help kristap Excel Worksheet Functions 12 June 17th 09 06:28 AM
Conditional SUMPRODUCT or SUMPRODUCT with Filters Ted M H Excel Worksheet Functions 4 August 14th 08 07:50 PM
sumproduct? sumif(sumproduct)? David Excel Worksheet Functions 3 July 13th 07 07:06 PM


All times are GMT +1. The time now is 03:19 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"