need dynamic range

kendel

Board Regular
Joined
Mar 2, 2010
Messages
133
Hello, I have the feeling many here will find this very basic stuff. When the vba code inserts this formula into cell S22 , it works perfectly, but when the code inserts it into S33 it sums ac22:ad22 again, naturally. With what can I replace the '22' to make the range totally independant of where on the worksheet it is, so it will sum whatever row it's in? As you see everything is relative.

Selection.select 'starts like this

'other stuff

ActiveCell.Offset(0, -2).Select
Selection.NumberFormat = "0"
Selection.formula= "=if((sum(ac22:ad22))>0,sum(ac22:ad22),"""")"
ActiveCell.Offset(0, 10).Select

Thanks in advance
Kendel
excel 2007 & 2010
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Possibly

Code:
Selection.Formula = "=if((sum(ac" & ActiveCell.Row & ":ad" & ActiveCell.Row & "))>0,sum(ac" & ActiveCell.Row & ":ad" & ActiveCell.Row & "),"""")"
 
Upvote 0
Maybe with R1C1 notation:
Code:
with activecell.Offset(0, -2)
    .NumberFormat = "0"
    .formulaR1C1 = "=if((sum(rc29:rc30))>0,sum(rc29:rc30),"""")"
end with
 
Upvote 0

Forum statistics

Threads
1,216,074
Messages
6,128,654
Members
449,462
Latest member
Chislobog

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