# Total column using last active cell

#### johndrew

##### Board Regular
I have the following code for totaling a column.

Code:
``````Dim LR As Long
With Sheets("inventory")
LR = .Range("e" & Rows.Count).End(xlUp).Row
.Range("e" & LR + 1).Value = WorksheetFunction.Sum(.Range("e1:e" & LR))
End With``````

The problem is it finds the previous total and places a new total just below it. What I need is to delete the old total and replace with the new total.

### Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

#### Norie

##### Well-known Member
Can you not just remove +1?

#### Misca

##### Well-known Member
LR is the row your old total is on but in your code you're using "LR + 1". Edit your "LR="-row by adding "-1" to it and your code should do what you're after.

#### johndrew

##### Board Regular
In E1 thru E5, I have then number (1) in each cell.
When I run the macro, I get 5 in E4
If I run again, I get 9 in E4
This is using the -1

#### Misca

##### Well-known Member
Where did you put the -1 to? Here's the code as it should be:
Code:
``````Dim LR As Long
With Sheets("inventory")
LR = .Range("e" & Rows.Count).End(xlUp).Row - 1
.Range("e" & LR + 1).Value = WorksheetFunction.Sum(.Range("e1:e" & LR))
End With``````
This piece of code replaces the last cell with new sum of everything above it: If you have 1's in E1:E5 this piece of code puts 4 in E5 no matter how many times you run the code.

#### johndrew

##### Board Regular
That removes my last entry in E5.

Here is what I used: Find the last inventory item used row in column (A) the go to column(E) and use that in the sum range and post one cell down.

Dim LR As Long
With Sheets("inventory")
LR = .Range("a" & Rows.Count).End(xlUp).Row
.Range("e" & LR + 1).Value = WorksheetFunction.Sum(.Range("e1:e" & LR))
End With

Replies
3
Views
174
Replies
5
Views
345
Replies
14
Views
359
Replies
4
Views
310
Replies
3
Views
98

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

1,163,715
Messages
5,833,284
Members
430,201
Latest member
Deepakpilla36

### 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.

### Which adblocker are you using?

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

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