ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   sumproduct or other way in vba, help and thanks (https://www.excelbanter.com/excel-programming/322016-sumproduct-other-way-vba-help-thanks.html)

jiang

sumproduct or other way in vba, help and thanks
 
dear all

a question about sumproduct function, in a sheet
A B C
1) 2 0 1
2) 4 5 6
3) 7 8 9
4) 10 11 12

Now I can use 2 sumproduct to make calculation,like
A1*C1+A2*C2 in one sumproduct
A4*C4 in another sumproduct
then I add result together.

My question is, is there anyway to make a formula
A1*C1+A2*C2+A4*C4. I could choose different array then define in more detail
because sumproduct ask all array should have same dimension.

Thanks in advance.

Bob Phillips[_6_]

sumproduct or other way in vba, help and thanks
 
You can just use SUM

=SUM(A1*C1,A2*C2,A4*C4)

--

HTH

RP
(remove nothere from the email address if mailing direct)


"jiang" wrote in message
...
dear all

a question about sumproduct function, in a sheet
A B C
1) 2 0 1
2) 4 5 6
3) 7 8 9
4) 10 11 12

Now I can use 2 sumproduct to make calculation,like
A1*C1+A2*C2 in one sumproduct
A4*C4 in another sumproduct
then I add result together.

My question is, is there anyway to make a formula
A1*C1+A2*C2+A4*C4. I could choose different array then define in more

detail
because sumproduct ask all array should have same dimension.

Thanks in advance.




jiang

sumproduct or other way in vba, help and thanks
 
Thanks, Bob

But it couldn't really solve my problem because I'm trying to make input
data easier, what I really want to know is whether a function could let user
select arrays and get calculation directly, instead of having to type formula.

My example is too simple, the real situation is that user might have to make
very long formula, and sometimes it's easy to make mistakes. It's much easier
if people just select array and ger result.

Anyway, thanks again for your prompt reply.
jiang

"Bob Phillips" wrote:

You can just use SUM

=SUM(A1*C1,A2*C2,A4*C4)

--

HTH

RP
(remove nothere from the email address if mailing direct)


"jiang" wrote in message
...
dear all

a question about sumproduct function, in a sheet
A B C
1) 2 0 1
2) 4 5 6
3) 7 8 9
4) 10 11 12

Now I can use 2 sumproduct to make calculation,like
A1*C1+A2*C2 in one sumproduct
A4*C4 in another sumproduct
then I add result together.

My question is, is there anyway to make a formula
A1*C1+A2*C2+A4*C4. I could choose different array then define in more

detail
because sumproduct ask all array should have same dimension.

Thanks in advance.





Bob Phillips[_6_]

sumproduct or other way in vba, help and thanks
 
This might work for you

Sub SumResult()
Dim rng1 As Range
Dim rng2 As Range
Dim cell As Range
Dim cRowOff As Long
Dim cColOff As Long
Dim tmp

Set rng1 = Application.InputBox("Select all cells in first range",
Type:=8)
Set rng2 = Application.InputBox("Select just the first cell in second
range", Type:=8)
cRowOff = rng2.Cells(1, 1).Row - rng1.Cells(1, 1).Row
cColOff = rng2.Cells(1, 1).Column - rng1.Cells(1, 1).Column
For Each cell In rng1
tmp = tmp + (cell.Value * cell.Offset(cRowOff, cColOff).Value)
Next cell

Set cell = Application.InputBox("Now select cell to put result",
Type:=8)
cell.Value = tmp

End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"jiang" wrote in message
...
Thanks, Bob

But it couldn't really solve my problem because I'm trying to make input
data easier, what I really want to know is whether a function could let

user
select arrays and get calculation directly, instead of having to type

formula.

My example is too simple, the real situation is that user might have to

make
very long formula, and sometimes it's easy to make mistakes. It's much

easier
if people just select array and ger result.

Anyway, thanks again for your prompt reply.
jiang

"Bob Phillips" wrote:

You can just use SUM

=SUM(A1*C1,A2*C2,A4*C4)

--

HTH

RP
(remove nothere from the email address if mailing direct)


"jiang" wrote in message
...
dear all

a question about sumproduct function, in a sheet
A B C
1) 2 0 1
2) 4 5 6
3) 7 8 9
4) 10 11 12

Now I can use 2 sumproduct to make calculation,like
A1*C1+A2*C2 in one sumproduct
A4*C4 in another sumproduct
then I add result together.

My question is, is there anyway to make a formula
A1*C1+A2*C2+A4*C4. I could choose different array then define in more

detail
because sumproduct ask all array should have same dimension.

Thanks in advance.








All times are GMT +1. The time now is 11:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com