SumIF with dynamic selections using VBA

kjohn25744

New Member
Joined
Oct 11, 2021
Messages
4
Office Version
  1. 365
Platform
  1. Windows
I need to sum a row using the sumIf function, however the number of rows change depending values selected on another sheet. I have a variable the calculates the last row (lRow) and would like to use that to calculate the offset for the value in VBA. Currently the VBA code is as follows:

ActiveCell.FormulaR1C1 = "=SUMIF(R[-l5]C[1]:R[-3]C[1],""Y"",R[-15]C:R[-3]C)

I would like to replace the [-15] with something like this [lRow -18] This would get me the correct offset of -15. I have tried several combinations, but can seen to get it to work. Not sure this is possible or not. Any ideas?
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
You can use a variable like
VBA Code:
ActiveCell.FormulaR1C1 = "=SUMIF(R[" & lrow - 18 & "]C[1]:R[-3]C[1],""Y"",R[" & lrow - 18 & "]C:R[-3]C)"
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,378
Members
448,955
Latest member
BatCoder

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