I know that in order to use Sumproduct in VBA I need to have the results set as value. For example, here's a code that I have been using and it works great:
With ActiveSheet.Range("P" & LR + 1)
.Formula = "=SUMPRODUCT($N$16:N" & LR & ", $P$16:P" & LR & ")/SUM($N$16:N" & LR & ")"
.Value2 = .Value2
I now have a formula that I'm having trouble with. It's a SUMPRODUCT with SumIf. I tried using the code above and adding the SUMIF piece, but it did not work. Here's what the current formula looks like:
Range("V" & lastrow + 11).Select
ActiveCell.Formula = "'=SUMPRODUCT(($A$11:$A$3798=""RSU"")*$AH$11:$AH$3798,$N$11:$N$3798)/SUMIF($A$11:$A$3798,""RSU"",$AH$11:$AH$3798)"
Range("V" & lastrow + 11).Select
This does not work. I can add an apostrophe to the formula and it will be entered as text in the cell. I then just have to remove the apostrophe to get the formula to work. I'm hoping that there is a way to skip the apostrophe step. Here's what the code looks like with the apostrophe:
Range("V" & lastrow + 11).Select
ActiveCell.Formula = "''=SUMPRODUCT(($A$11:$A$3798=""RSU"")*$AH$11:$AH$3798,$N$11:$N$3798)/SUMIF($A$11:$A$3798,""RSU"",$AH$11:$AH$3798)"
Range("V" & lastrow + 11).Select
Any help/suggestion is much appreciated.
Thanks,
With ActiveSheet.Range("P" & LR + 1)
.Formula = "=SUMPRODUCT($N$16:N" & LR & ", $P$16:P" & LR & ")/SUM($N$16:N" & LR & ")"
.Value2 = .Value2
I now have a formula that I'm having trouble with. It's a SUMPRODUCT with SumIf. I tried using the code above and adding the SUMIF piece, but it did not work. Here's what the current formula looks like:
Range("V" & lastrow + 11).Select
ActiveCell.Formula = "'=SUMPRODUCT(($A$11:$A$3798=""RSU"")*$AH$11:$AH$3798,$N$11:$N$3798)/SUMIF($A$11:$A$3798,""RSU"",$AH$11:$AH$3798)"
Range("V" & lastrow + 11).Select
This does not work. I can add an apostrophe to the formula and it will be entered as text in the cell. I then just have to remove the apostrophe to get the formula to work. I'm hoping that there is a way to skip the apostrophe step. Here's what the code looks like with the apostrophe:
Range("V" & lastrow + 11).Select
ActiveCell.Formula = "''=SUMPRODUCT(($A$11:$A$3798=""RSU"")*$AH$11:$AH$3798,$N$11:$N$3798)/SUMIF($A$11:$A$3798,""RSU"",$AH$11:$AH$3798)"
Range("V" & lastrow + 11).Select
Any help/suggestion is much appreciated.
Thanks,