#1   Report Post  
Junior Member
 
Posts: 1
Default Userrange to formula

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 the user can select a range and after pressing ok this should be converted 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 function but I couldn't find out a solution. Can someone help me?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,872
Default Userrange to formula

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
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Build formula using field values as text in the formula referencing another workbook solardirect Links and Linking in Excel 6 June 4th 12 10:47 PM
Regression Leverage Formula (Jerry W. Lewis or Mike Middleton)already have DFITS formula PJ[_3_] Excel Worksheet Functions 2 June 2nd 10 03:45 PM
Formula expected end of statement error, typing formula into cell as part of VBA macro [email protected] Excel Programming 1 July 20th 06 07:58 PM
Commenting custom formula fields/formula on formula editor Muxer Excel Programming 2 July 24th 03 01:02 AM


All times are GMT +1. The time now is 08:50 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"