Total a row in VB

MJA

Board Regular
Joined
Feb 18, 2002
Messages
79
Hello once more,

I have a serie of numbers in A1, B1, C1 to x1.
I want to total the numbers from A1 to x1, the answer must stand in the cell next to x1!!!

[A1].End(xlToRight)(1, 2).Value = Application.Sum(Range([A1], [A!].End(xlToRight)))

This does the trick, BUT when I change a number the total doesn’t change.
I must play the macro again and then it will.
But I only want the macro to play just once.
Therefore it must be a formula that stands in x1.
How do I do that?
The solution must be in VB!
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
The following might do the trick, it will total the values in the first row from A1 to X1 and put the result in Y1: -

Private Sub Worksheet_Change(ByVal Target As Excel.Range)

If Target.Count > 1 Then Exit Sub
If Target.Row <> 1 Then Exit Sub
Cells(1, 25).Formula = "=SUM(A1:X1)"

End Sub
 
Upvote 0
On 2002-02-22 00:34, MJA wrote:
Hello once more,

I have a serie of numbers in A1, B1, C1 to x1.
I want to total the numbers from A1 to x1, the answer must stand in the cell next to x1!!!

[A1].End(xlToRight)(1, 2).Value = Application.Sum(Range([A1], [A!].End(xlToRight)))

This does the trick, BUT when I change a number the total doesn’t change.
I must play the macro again and then it will.
But I only want the macro to play just once.
Therefore it must be a formula that stands in x1.
How do I do that?
The solution must be in VB!


Dim cell As Range
Set cell = [A1].End(xlToRight)(1, 2)
cell.Formula = "=SUM(A1:OFFSET(" & cell.Address(False, False) & ",0,-1))"
 
Upvote 0
On 2002-02-22 01:22, Tikas A. Planck wrote:
On 2002-02-22 00:34, MJA wrote:
Hello once more,

I have a serie of numbers in A1, B1, C1 to x1.
I want to total the numbers from A1 to x1, the answer must stand in the cell next to x1!!!

[A1].End(xlToRight)(1, 2).Value = Application.Sum(Range([A1], [A!].End(xlToRight)))

This does the trick, BUT when I change a number the total doesn’t change.
I must play the macro again and then it will.
But I only want the macro to play just once.
Therefore it must be a formula that stands in x1.
How do I do that?
The solution must be in VB!


Dim cell As Range
Set cell = [A1].End(xlToRight)(1, 2)
cell.Formula = "=SUM(A1:OFFSET(" & cell.Address(False, False) & ",0,-1))"

Man you're great!
How is it you know so much of VB?!?!
 
Upvote 0
On 2002-02-22 01:22, Tikas A. Planck wrote:
On 2002-02-22 00:34, MJA wrote:
Hello once more,

I have a serie of numbers in A1, B1, C1 to x1.
I want to total the numbers from A1 to x1, the answer must stand in the cell next to x1!!!

[A1].End(xlToRight)(1, 2).Value = Application.Sum(Range([A1], [A!].End(xlToRight)))

This does the trick, BUT when I change a number the total doesn’t change.
I must play the macro again and then it will.
But I only want the macro to play just once.
Therefore it must be a formula that stands in x1.
How do I do that?
The solution must be in VB!


Dim cell As Range
Set cell = [A1].End(xlToRight)(1, 2)
cell.Formula = "=SUM(A1:OFFSET(" & cell.Address(False, False) & ",0,-1))"

If I want to do exactly the same but instead of rows I have columns. E.g. numbers in A1:Ax, I want the total in the cell under Ax.
Then what code do I get.....???
 
Upvote 0
Dim cell As Range
Set cell = [A1].End(xlDown)(2, 1)
cell.Formula = "=SUM(A1:OFFSET(" & cell.Address(False, False) & ",-1,0))"
 
Upvote 0

Forum statistics

Threads
1,214,385
Messages
6,119,208
Members
448,874
Latest member
b1step2far

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