Userrange to formula

K

Klaasv

Dear all,

I am new with the VBA part of Excel but I want to learn the language
Now I came up with the following problem. I want a pop upbox where th
user can select a range and after pressing ok this should be converte
to a formula in cell c1 (formula= "=sum(selected range)").

Now I have this:
Sub Test()

Set UserRange = Application.InputBox("Hallo", "Select your range:")
Rng = Application.WorksheetFunction.Sum(UserRange)
Range("C1").Select
Selection.Value = Rng

End Sub

After the popup it stops. Most likely because I misuse the Sum functio
but I couldn't find out a solution. Can someone help me
 
C

Claus Busch

Hi,

Am Wed, 10 Apr 2013 14:00:15 +0000 schrieb Klaasv:
Now I have this:
Sub Test()

Set UserRange = Application.InputBox("Hallo", "Select your range:")
Rng = Application.WorksheetFunction.Sum(UserRange)
Range("C1").Select
Selection.Value = Rng

End Sub

try:

Sub Test()
Dim UserRange As Range

Set UserRange = Application.InputBox("Hallo", _
"Select your range:", Type:=8)
If Not UserRange Is Nothing Then
[C1] = WorksheetFunction.Sum(UserRange)
End If

End Sub


Regards
Claus Busch
 

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

Top