last row auto sum ?

Joshua88

New Member
Joined
Apr 27, 2018
Messages
20
hello every one, I have a line of code that I'm working on, it auto sums the data from column "A" and puts the sum, one cell below the last, what I'm trying to do is have to sum appear in "W1" instead of the cell below the last, any thought?

[CODEWith Sheets("DataDump8")
Dim Lr As Long
Lr = Cells(Rows.Count, "A").End(xlUp).Row + 1
Cells(Lr, "A").Formula = "=SUM(A1:A" & Lr - 1 & ")*4"
End With

][/CODE]
 
Last edited:

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Try
Code:
Range("W1").Formula =
 
Upvote 0
ok so how about this I ran into an issue with the code running on a home sheet and not on my data dump sheet, I made a change and it runs on the data sheet but instead of getting a sum I get #NAME ?
any idea ?

Code:
With Sheets("DataDump8")
'Dim Lr As Long
Lr = Cells(Rows.Count, "A").End(xlUp).Row + 1
Sheets("DataDump8").Range("W1").Formula = "=SUM(A:A" & Lr - 1 & ")*4"
End With
 
Upvote 0
You're missing the row reference from the 1st A
Code:
With Sheets("DataDump8")
   Dim Lr As Long
   Lr = Cells(Rows.Count, "A").End(xlUp).Row 
   .Range("W1").Formula = "=SUM(A[COLOR=#ff0000]1[/COLOR]:A" & Lr  & ")*4"
End With
 
Upvote 0
ok I added the 1 it works on the active data dump8 sheet I get a sum of 100 as I should, but when I select my home sheet and make that active, and run the code I get a sum of 4 ? dosent seem to be totaling column A on datadump sheet?
 
Upvote 0
You'll need to put the sheet name in front of the range
 
Upvote 0
thanks for the reply
I still get the same thing a sum of 4 when home is active and get a sum 100 when data dump is active, 100 is correct just not when home is active, is there a better way of achieving the same results?

Code:
With Sheets("DataDump8")
   Dim Lr As Long
   Lr = Cells(Rows.Count, "A").End(xlUp).Row
   Sheets("DataDump8").Range("W1").Formula = "=SUM(A1:A" & Lr & ")*4"
 
Upvote 0
I found that the code below works

[CODESheets("DataDump8").Range("W1").FormulaR1C1 = "=SUMIF(C[-21],C[-21],C[-22])*4"][/CODE]

there's more then one way to skin a cat :)
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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