View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Per Jessen[_2_] Per Jessen[_2_] is offline
external usenet poster
 
Posts: 703
Default Summing random cells as you click on them

Hi

Insert a button from the "control Toolbox" menu on your sheet, then
right click on the button and select "View code". Paste the code below
into the code window. Change the TargetCell as desired and return to
the worksheet. Click "Exit design mode"

Private Sub CommandButton1_Click()
TargetCell = "H2" ' Change to suit
Range(TargetCell, Range(TargetCell).End(xlDown)).ClearContents
For Each cell In Selection
Range(TargetCell).Offset(off, 0) = cell.Value
MyResult = MyResult + cell.Value
off = off + 1
Next
Range(TargetCell).Offset(off, 0) = MyResult
End Sub

Now you can click the first cell to add, then hold down "CTRL" while
clicking further cells to add. Click on your button when you are done
and watch the result.

Hopes it helps.

Regards,
Per

On 3 Dec., 00:29, Ben in CA <Ben in
wrote:
I need to create a "program" with an Excel document that allows me to click a
button like "start adding" and then I can click on random cells (well, they
wouldn't actually be random, but not in any series of columns or rows), and
the contained values to be copied to successive cells in an empty column on
the side, that I can then have a Sum setup up on.

Basically, I have different pieces of equipment listed in an Excel
spreadsheet, along with various options. (Several hundred) I want to be able
to select which ones (even just by clicking on the price/value), and
automatically add them together - currently this is done on paper. (The costs
of the various options, etc. are scattered about, and aren't all in a
particular row or column.)

Once I'm done calculating it, probably I'd need to have a "Stop adding"
button that I could press and then it would stop calculating the value.

Preferably it only copies the actual number in the cells to the new
location, as many of the cells are themselves calculated by formulas.

Can anyone think of a way of doing this? I've been looking around for a way
to do this, but I haven't found anything that will do it yet.

Thanks in advance to anyone who solves this problem!