Sum Range Values using Type 8 Input Box

bajlewis

New Member
Joined
Nov 1, 2011
Messages
12
Hello,

I'm trying to sum a range of values selected by a user via a type 8 input box and set it as a variable for later evaluation. Can somebody please help? Thank you, find the vba below:

Sub formulacheck2()


Dim Y As String
Dim X As String
Dim R As Range
Dim ws As Worksheet
Dim N As Long
Dim B As Long


On Error Resume Next
Application.DisplayAlerts = False

Set R = Application.InputBox(Prompt:= _
"Please select the range the formula check is contained in.", _
Title:="SPECIFY RANGE", Type:=8)

On Error GoTo 0

Application.DisplayAlerts = True



If R Is Nothing Then

Exit Sub

Else

N = Application.WorksheetFunction.Sum(R)
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Other than an End If and End Sub at the end, the only thing I would change is to declare N as Double.

What problem are you having with the code?
 
Upvote 0
I was referencing another sheet, i found that if I changed Application.worksheet.sum(...) to Application.Sum it would work, thanks for the reply
 
Upvote 0

Forum statistics

Threads
1,216,038
Messages
6,128,450
Members
449,453
Latest member
jayeshw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top