• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Add 'n' numbers from a selected cell in user form pop-up window

nagovind

Member
Dear All,
Is there is any way to add the selected cell from user form and display the result as a pop-up window itself

Say A1 A2 A3 cells have data
After clicking a shortcut say ctr+shft+a, window has to popup ask for number of variables to add once it is given as 3 (say, n) it has to allow to select n number of cells that contains data, once after given input it has to add the data and produce result in the popup window itself

Kindly advise
Regards
Govind
 
Try these and modify to suit

Code:
Sub Sum_Range()
    Dim No_Cells As Long
    No_Cells = InputBox("Please enter the number of cells to Sum", "Sum Range")
   
    Dim sum_rng As Range
    Set sum_rng = Range("A1:A" & CStr(No_Cells))
   
    Dim my_sum As Double
    my_sum = Application.WorksheetFunction.Sum(sum_rng)
    MsgBox ("Sum of " & sum_rng.Address & " = " & CStr(my_sum))
End Sub

Code:
Sub Sum_Range_Selection()
    Dim my_sum As Double
    my_sum = Application.WorksheetFunction.Sum(Selection)
    MsgBox ("Sum of " & Selection.Address & " = " & CStr(my_sum))
End Sub

To assign these to a key combo have a read of Point #13 at:
 
Dear Hui,

Thank you for your inputs,
Code:
Code:
Sub RangeSelectionPrompt()
    Dim rng As Range
    Set rng = Application.InputBox("Select a range", "Obtain Range Object", Type:=8)

    MsgBox "The cells selected were " & rng.Address
End Sub
Actually I'm looking for the code as above, once we enter how many numbers to be added then it has asked for 'n' times pop-up then for each pop-up user has to select the cells as applicable in a random way say the data is in different cells

If n = 5 then it has to ask for 5 times input, for each input user will select 1 cell at a time say A1 in first popup second CD2, third B6 etc

Finally, the output shall be added (5 input addition, i.e 'n' input addition) and message will display the addition result

Regards
Govind
 
Last edited by a moderator:
Dear Hui,

Got it THANKS, closed

Code:
Sub RangeSelectionPrompt()
    Dim rng As Range
    c = 0
    nc = InputBox("Please enter the number of cells to Sum", "Sum Range")
    For i = 1 To nc
    Set rng = Application.InputBox("Select a range", "Obtain Range Object", Type:=8)
    c = c + rng
    Next i
    'MsgBox "The cells selected were " & rng.Address
    MsgBox c
   
End Sub
Regards
Govind
 
Last edited by a moderator:
Back
Top