The reference changes when I insert a row?!?! Help

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've created a worksheet that uses a macro. The macro adds a line at the top
of the worksheet. I have some cells that total from different columns. I
thought that changing the formula in the totals cells to an absolute
reference should work...I want the formula in the total box to always add the
cells from D9 on down the line...In my totals cell I wrote =sum($D$9:$D$500).
When I run the macro, it moves all of my rows down 1 row and inserts a new
row 9. When I click on my totals cell to read the formula, it now reads
=sum($D$10:$D$501). HELPPPPP!
 
ntscott said:
I've created a worksheet that uses a macro. The macro adds a line at the top
of the worksheet. I have some cells that total from different columns. I
thought that changing the formula in the totals cells to an absolute
reference should work...I want the formula in the total box to always add the
cells from D9 on down the line...In my totals cell I wrote =sum($D$9:$D$500).
When I run the macro, it moves all of my rows down 1 row and inserts a new
row 9. When I click on my totals cell to read the formula, it now reads
=sum($D$10:$D$501). HELPPPPP!

Why not get the macro to insert a formula. If the total goes in d8 add the
line

range("D8").formula = "=sum(D9:D500)"

Adding the extra rows will make the formula future proof.

Regards
Peter
 
This formula will *always* start your range at D9:
=SUM(INDIRECT("$D$9"):$D$500)

Note: Inserting rows will extend the range downwards.

Does that help?

Ron
 
Start your sum from one row above, ie row 8 and make that row blank (maybe
shrink it a bit too)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top