Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Summing random cells as you click on them

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!
  #2   Report Post  
Posted to microsoft.public.excel.misc
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!


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Summing random cells as you click on them

Maybe you could just ask the user to select the range in the macro and then
cycle through the selection:

Option Explicit
Sub testme()
Dim myRng As Range
Dim myCell As Range
Dim oWks As Worksheet
Dim oRow As Long

Set myRng = Nothing
On Error Resume Next
Set myRng = Application.InputBox(prompt:="Select a range", Type:=8)
On Error GoTo 0

If myRng Is Nothing Then
Exit Sub 'user hit cancel
End If

Set oWks = Workbooks.Add(1).Worksheets(1)

oRow = 0
For Each myCell In myRng.Cells
oRow = oRow + 1
oWks.Cells(oRow, "A").Value = myCell.Address(external:=True)
With oWks.Cells(oRow, "B")
.NumberFormat = myCell.NumberFormat
.Value = myCell.Value
End With
Next myCell

With oWks
.Cells(oRow + 1, "B").FormulaR1C1 = "=sum(r1c2:r[-1]c)"
.UsedRange.Columns.AutoFit
End With

End Sub


Ben in CA 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!


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 37
Default Summing random cells as you click on them

Ben,

For my example, I placed values in a 10 by 10 array on Sheet 1 (the range
A1:J10). I want values that I click to be in column "L" beginning in row 2.
I have a sub to turn the listing operation on and one to turn it off. You
can put command buttons on the sheet and attach the macro to the buttons.

In Module1 I have:

'------------------------------------
Public ExtractOn As Boolean

Sub ExtractBegin()
ExtractOn = True
End Sub

Sub ExtractStop()
ExtractOn = False
End Sub

'------------------------------------

Then, on sheet 1 I have this event driven subroutine

'--------------------------------------

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rngList As Range
If ExtractOn = True Then
Application.EnableEvents = False
Set isect = Application.Intersect(Target, Range("A1:J10"))
If Not isect Is Nothing Then
Set rngList = Cells(Rows.Count, "L").End(xlUp)(2)
rngList.Value = Target.Value
End If
Application.EnableEvents = True
End If
End Sub

'---------------------------------------

Steve Yandl



"Ben in CA" <Ben in wrote in message
...
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!



  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,346
Default Summing random cells as you click on them

Hi,

Before we get started creating a fancy macro to do this, see if this is good
enough:

Click the first cell with numbers, hold down the Ctrl key and click any
other cell with numbers. Observe the right side of the Status Bar. Most
likely you will see SUM = 123,456 or some number. If you don't see SUM then
right click on the right side of the status bar and from the pop-up choose
SUM, noting you can do Average, Count, Max and Min.

You can highlight any cells you want and you will see the calcualtion. You
can highlight by dragging the mouse, doing Shift+Click, using Ctrl+Click or
any other method of the 250 ways you can select.

If this helps, please click the Yes button,

Cheers,
Shane Devenshire

"Ben in CA" 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!



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 31
Default Summing random cells as you click on them

Thank you for all the answers so far!

I'll try them and see if they'll work.

Ben


"Ben in CA" 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!

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 31
Default Summing random cells as you click on them

Per's solution works great!

Thank you to Dave, Shane, and Steve as well - but I think for now Per's idea
will do what I need.

Have a great day!
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I sum up random cells Josh W Excel Worksheet Functions 25 April 2nd 23 07:56 PM
Click = Random Charaters Into A Cell Chris Excel Worksheet Functions 1 June 5th 08 12:10 PM
Summing Cells with #N/A Joan NYC Excel Worksheet Functions 8 February 26th 07 07:57 AM
Summing of Two cells does not sum!! Joe D Excel Discussion (Misc queries) 2 July 17th 05 10:53 PM
Summing some cells Jim Excel Worksheet Functions 1 February 17th 05 03:06 AM


All times are GMT +1. The time now is 07:56 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"