VBA - Use FinalRow value in SUMIF formula

Bad_Handle

New Member
Joined
Nov 12, 2009
Messages
26
Hello, <o:p></o:p>
<o:p></o:p>
Can someone please help with the syntax to use VBA for including FinalRow value in a SUMIF formula? Hope this is on the right track. The goal is to keep the formula available in the cell after running the macro.<o:p></o:p>
<o:p>

</o:p>
<o:p></o:p>
'Determine Last Row of Imported Dataset<o:p></o:p>
Dim FinalRow As Long<o:p></o:p>
FinalRow = Range("A1048576").End(xlUp).Row<o:p></o:p>
<o:p></o:p>
'Cell to Change: H10 <o:p></o:p>
'Change SumIf Formulas to include final row of Data instead of Row 20000<o:p></o:p>
'Original --> Range("H10").FormulaR1C1 = "=SUMIF(R14C17:R20000C17,R10C1,R14C:R20000C)"<o:p></o:p>
<o:p></o:p>
Range("H10").FormulaR1C1 = "=SUMIF(R14C17:R[FinalRow]C17,R10C1,R14C:R[FinalRow]C)"<o:p></o:p>
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Try this:

.FormulaR1C1 = "=SUMIF(R14C17:R["&FinalRow&"]C17,R10C1,R14C:R["&FinalRow&"]C)"<o:p></o:p>
 
Upvote 0
My bad

.FormulaR1C1 = "=SUMIF(R14C17:R" & FinalRow & "C17,R10C1,R14C:R" & FinalRow & "C)"
 
Upvote 0

Forum statistics

Threads
1,216,759
Messages
6,132,556
Members
449,735
Latest member
Gary_M

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
Back
Top