It sounds like you are creating something like a "shopping cart" setup. You
might want to consider using check boxes adjacent the prices you want to sum
instead. You wouldn't be summing selected cells but the cells adjacent
checkmarked check boxes. Just a thought.
Responding to your request, the following is my suggestion:
1. Put two command buttons on the worksheet and assign the appended two
macros. Change the captions of the command buttons to "Sum" and "Clear"
respectively. Alternatively, do this with tool bar buttons added to the
Worksheet Menu Bar. If you choose the second option, then you will likely
want to add them programmatically on wb_open and make them Temporary else
they will still be there when another wb is open and cause problems if
clicked.
2. Type "Results:" in the desired cell in the first row (note the colon
":"). It must be to the right of your data.
3. Now select the prices you want to sum using the <Ctrl> button to select
noncontiguous cells.
4. Click the first "Sum" button. The result will be pasted to the right of
either the word "Sum:" or the previous result.
5. Click the "Clear" button to clear the results.
Sub SumSelection()
Dim ws As Worksheet
Dim c As Range
Set ws = Sheets("Sheet1")
Set c = ws.Cells(1, Columns.Count).End(xlToLeft)(1, 2)
c.Value = Application.Sum(Selection)
End Sub
Sub ClearResults()
Dim ws As Worksheet
Dim c As Range, c2 As Range
Set ws = Sheets("Sheet1")
Set c = ws.Rows(1).Find("Results:")(1, 2)
Set c2 = ws.Cells(1, Columns.Count).End(xlToLeft)
ws.Range(c, c2).ClearContents
End Sub
Regards,
Greg
> Awesome, that is a great solution! Thanks!
>
[quoted text clipped - 6 lines]
>
> Chaser
Greg Wilson - 11 Jun 2006 20:13 GMT
Point 4 should say:
4. Click the "Sum" button. The sum of the selected cells will be pasted to
the right of either the word "Results:" or the previous result.
Greg
> It sounds like you are creating something like a "shopping cart" setup. You
> might want to consider using check boxes adjacent the prices you want to sum
[quoted text clipped - 48 lines]
> >
> > Chaser
Greg Wilson - 11 Jun 2006 21:59 GMT
Chaser,
Sorry, minor change required for ClearResults routine. Should be:
Sub ClearResults()
Dim ws As Worksheet
Dim c As Range, c2 As Range
Set ws = Sheets("Sheet1")
Set c = ws.Rows(1).Find("Results:")(1, 2)
Set c2 = ws.Cells(1, Columns.Count).End(xlToLeft)(1, 2)
ws.Range(c, c2).ClearContents
End Sub
Greg
> It sounds like you are creating something like a "shopping cart" setup. You
> might want to consider using check boxes adjacent the prices you want to sum
[quoted text clipped - 48 lines]
> >
> > Chaser