Use variable to define cell in sumif statement

sleibo

New Member
Joined
Aug 28, 2024
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
I am trying to use sumif statement with variable cell locations. In this snippet, sumif works as it should when R1C1 or absolute cell locations are used, but I can not get it to work using variable for cell location as in last line. Assist?

'
Dim Nmbr As Long
Nmbr = 32
ActiveCell.FormulaR1C1 = _
"=SUMIF(R[6]C[-7]:R[28]C[-7],""RNT Rent"",R[6]C[-6]:R[28]C[-6])"
Selection.ClearContents
ActiveCell.Formula = "=sumif(E10:e32,""RNT Rent"",F10:f32)"
Selection.ClearContents
ActiveCell.Formula = "=sumif(""E10:e""&Nmbr,""RNT Rent"",F10:f32)"
End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Beware where strings starts and ends; try
VBA Code:
ActiveCell.Formula = "=sumif(E10:e" & Nmbr & ",""RNT Rent"",F10:" & Nmbr & ")"
 
Upvote 0
Solution
Thanks, Anthony47. Once I put in the extra "F" (after F10:) it worked!
 
Upvote 0

Forum statistics

Threads
1,223,900
Messages
6,175,276
Members
452,629
Latest member
SahilPolekar

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