Convert excel formula to vba

loopa1

Board Regular
Joined
Sep 3, 2006
Messages
156
Hi all

I want to use sumproduct formula in approx. 50,000 cells, but asking excel to calculate this "kills" excel.

Is there anyway I can use this formula in VBA so instead of adding the formula to each cell and then calculating the value for each cell, it just calculates the value in vba and places it in the appropriate cell.

Current working excel formula is as follows...

=IF($A5="","",SUMPRODUCT(--($A5=Sheet1!$CC$2:$CC$5028)*(C$2=Sheet1!$AD$2:$AD$5028)*($B5=Sheet1!$H$2:$H$5028))+SUMPRODUCT(--($A5=Sheet1!$CC$2:$CC$5028)*(C$2=Sheet1!$AW$2:$AW$5028)*($B5=Sheet1!$H$2:$H$5028)))

$A5 will be over the range of $A5 to $A3716
$B5 will be over the range of $B5 to $B3716
C$2 will be over the range of C$2 to ES$2
and the result of this calculation will be placed in C5:ES3716

Thanks.
 

Some videos you may like

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

AMAS

Active Member
Joined
Apr 11, 2010
Messages
472
Hi,

This should get you started:

Code:
Sub Trial()
With Range("C5:ES3716")
.Formula = "=IF(R[4]C1="""","""",SUMPRODUCT(--(R[4]C1=Sheet1!R2C81:R5028C81)*(R2C[2]=Sheet1!R2C30:R5028C30)*(R[4]C2=Sheet1!R2C8:R5028C8))+SUMPRODUCT(--(R[4]C1=Sheet1!R2C81:R5028C81)*(R2C[2]=Sheet1!R2C49:R5028C49)*(R[4]C2=Sheet1!R2C8:R5028C8)))"
.Value = .Value
End With
End Sub

AMAS
 

loopa1

Board Regular
Joined
Sep 3, 2006
Messages
156
Thanks AMAS, but somethings not right here...it's not producing the right results. I'm trying to understand why, but struggling to understand the syntax of some of your formula.
 

AMAS

Active Member
Joined
Apr 11, 2010
Messages
472
Hi,

Which is the first cell where your forumla goes (e.g. C5)?

AMAS
 

loopa1

Board Regular
Joined
Sep 3, 2006
Messages
156
It's ok - managed to do it with a series of if statements, probably not the best way of doing it, but it's working.

Thanks for your help.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,964
Messages
5,599,069
Members
414,281
Latest member
Engjamal2021

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top