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


Hi

I have two columns on which I want to run a sumproduct formula using
VBA. Column D has names and column O has what I want to match it with.
I have two cells containing the information for the criteria namely Q3
= John and S1 = AGREE. I would like the result put into S2

I want to run this using a command button rather than have the formula
in the cell.

If I put this formula into the cell S2 then it works fine

=SUMPRODUCT((D2:D2500=Q3)*(O2:O2500=S1))

However if I create a button and have this code, I get a #Value error
in S3 instead of the result

Private Sub CommandButton2_Click()

Cells(3, "S").value =
Evaluate("=SUMPRODUCT((D2:D2500=Q3)*(O2:02500=S1)) ")

End Sub

If I leave out the evaluate and just have

Cells(3, "S").value =SUMPRODUCT((D2:D2500=Q3)*(O2:02500=S1))

then I get a syntax error

Is there anything obvious I'm doing wrong??

many thanks

Steve


--
ghobbit
------------------------------------------------------------------------
ghobbit's Profile: http://www.excelforum.com/member.php...o&userid=12385
View this thread: http://www.excelforum.com/showthread...hreadid=544477

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default sumproduct in VBA

Is there anything obvious I'm doing wrong??

an un-obvious typo, change

O2:02500=S1
to
O2:o2500=S1

Regards,
Peter T

"ghobbit" wrote in
message ...

Hi

I have two columns on which I want to run a sumproduct formula using
VBA. Column D has names and column O has what I want to match it with.
I have two cells containing the information for the criteria namely Q3
= John and S1 = AGREE. I would like the result put into S2

I want to run this using a command button rather than have the formula
in the cell.

If I put this formula into the cell S2 then it works fine

=SUMPRODUCT((D2:D2500=Q3)*(O2:O2500=S1))

However if I create a button and have this code, I get a #Value error
in S3 instead of the result

Private Sub CommandButton2_Click()

Cells(3, "S").value =
Evaluate("=SUMPRODUCT((D2:D2500=Q3)*(O2:02500=S1)) ")

End Sub

If I leave out the evaluate and just have

Cells(3, "S").value =SUMPRODUCT((D2:D2500=Q3)*(O2:02500=S1))

then I get a syntax error

Is there anything obvious I'm doing wrong??

many thanks

Steve


--
ghobbit
------------------------------------------------------------------------
ghobbit's Profile:

http://www.excelforum.com/member.php...o&userid=12385
View this thread: http://www.excelforum.com/showthread...hreadid=544477



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


Hi Don and Pete

Thanks for your replies

Public Sub CommandButton2_Click()

Cells(3, "S").Value =
Evaluate("=SUMPRODUCT((D2:D2500=range("Q3"))*(O2:O 2500=range("S1")))")

End Sub

gives me a syntax error when I click on the button with the Public Sub
CommandButton2_Click() bit highlighted in yellow

and if I delete the last parentheses it gives me a compile error with
Q3 highlighted saying expected list seperator or ). So I put the
parentheses back only to get the same error.

and as far as I can see there are no typo's

This is really proving quite frustrating because it looks like it
should work and the formula does work if I put it in the cell but I
really dont want to to do this.

any idea?

many thanks for your input

regards

Steve


--
ghobbit
------------------------------------------------------------------------
ghobbit's Profile: http://www.excelforum.com/member.php...o&userid=12385
View this thread: http://www.excelforum.com/showthread...hreadid=544477

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

and as far as I can see there are no typo's

Well there's a typo in the code you posted, if corrected as I suggested the
formula works

still can't see it - try this

Evaluate("=SUMPRODUCT((D2:D2500=Q3)*(O2:O2500=S1)) ")

(copy & paste it)

don't really need the "=" before Sumproduct, but it works either way

Regards,
Peter T


"ghobbit" wrote in
message ...

Hi Don and Pete

Thanks for your replies

Public Sub CommandButton2_Click()

Cells(3, "S").Value =
Evaluate("=SUMPRODUCT((D2:D2500=range("Q3"))*(O2:O 2500=range("S1")))")

End Sub

gives me a syntax error when I click on the button with the Public Sub
CommandButton2_Click() bit highlighted in yellow

and if I delete the last parentheses it gives me a compile error with
Q3 highlighted saying expected list seperator or ). So I put the
parentheses back only to get the same error.

and as far as I can see there are no typo's

This is really proving quite frustrating because it looks like it
should work and the formula does work if I put it in the cell but I
really dont want to to do this.

any idea?

many thanks for your input

regards

Steve


--
ghobbit
------------------------------------------------------------------------
ghobbit's Profile:

http://www.excelforum.com/member.php...o&userid=12385
View this thread: http://www.excelforum.com/showthread...hreadid=544477





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default sumproduct in VBA


Thanks Peter

Couldnt see it for looking

works fine now

regards

steve


--
ghobbit
------------------------------------------------------------------------
ghobbit's Profile: http://www.excelforum.com/member.php...o&userid=12385
View this thread: http://www.excelforum.com/showthread...hreadid=544477

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? Rene Excel Discussion (Misc queries) 13 October 31st 08 06:38 PM
SUMPRODUCT help Gaurav[_4_] Excel Worksheet Functions 2 October 31st 08 05:13 PM
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 10:24 AM.

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

About Us

"It's about Microsoft Excel"