PDA

View Full Version : [SOLVED:] VBA SUM() with pop-up window to select range



dmw
06-12-2015, 06:49 AM
Hi,

I'm trying to find out how I can create a pop-up window in VBA asking to select a range myself, click "ok", and it then returns the SUM() value in the cell "D5". Is there a way to do this? I'll be honest, I don't know how to do this at all.

I have attached an example excel spreadsheet for reference.

The range I would like to select should be in column "B" starting in "B10". I appreciate any help.

Paul_Hossler
06-12-2015, 07:07 AM
1. Pretty tricky -- pasting a picture of the worksheet cells -- had me going for a bit :devil2:

2. Not a lot of error checking, but this seems to do what you're looking for



Option Explicit
Sub SumSelection()
Dim rData As Range

On Error Resume Next
Set rData = Application.InputBox("Select the cells to sum and [OK], or [Cancel] to exit", "Summing Cells", "", , , , , 8)
If Not TypeOf rData Is Range Then Exit Sub
On Error GoTo 0

rData.Parent.Range("D5").Value = Application.WorksheetFunction.Sum(rData)
End Sub

dmw
06-12-2015, 07:28 AM
Paul,

that's just what I was looking for. Thank you for your help! I have been learning a lot since I joined this forum, it's awesome.