Right click and iterate through selection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to drag a selection box around a group of cells in one column
(a5..a10) for example and then when the right-click is pressed give the user
the option to click "Process" and then iterate through each cell entry in the
range.

How do I do that? I 've got a fair idea for the right-click thing but I'm
not sure how to step through each cell in the range and process the numbers.

Thanks for any help
Paul
 
Hello Paul,

Here is a code example that sums the values of the cells selected when
the user Right Clicks the selection. The sum of the Selected cells is
placed below the last cell in the selection.

Remember that setting Cnacel to True in this event will disable the
context menus.

EXAMPLE:


Code:
--------------------
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)

Dim Cell
Dim N

Cancel = True

For Each Cell In Selection
N = N + Cell.Value
Next Cell

Selection.Cells(1, 1).End(xlDown).Value = N

End Sub
 

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

Back
Top