Adding current selection

R

RICOUK

I am not even sure that this can be done and I have no idea where t
start on this one.
Basically, I need a macro to add up the user selected cells and displa
the result in the last row left one.
for example.
user selects cells C3:C10
the result needs to be displayed in B10

The user then selects C11:C32
the results need to be displayed in B32

The user can select any number of cells within colum C and the cell ro
can be anything.

Is there code which would allow this to happen using a button to star
the macro after the highlighting of the cells?

Thanks in advance
 
G

Gord Dibben

Sub Sum_Selected2()

Dim Rng As Range, rng1 As Range
Set Rng = Selection
Set rng1 = Rng.Areas(Rng.Areas.Count)
Set rng1 = rng1(rng1.Rows.Count, rng1.Columns.Count)
rng1.Offset(0, -1).Formula = "=Sum(" & Rng.Address & ")"

End Sub


Gord Dibben Excel MVP
 
J

JE McGimpsey

One way:

Public Sub Button1_Click()
With Selection
.Item(.Count).Offset(0, -1).Value = _
Application.Sum(.Cells)
End With
End Sub

Note that there's no error checking
 
R

RICOUK

Thanks for that, my project is nearly complete, now I have just got t
tidy up everything
 

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

Top