|
-
May 6th, 2005, 09:08 AM
#1
Thread Starter
Junior Member
an extreme newbie vba question
How do I get a the sum of a range of cells to display in a msgbox when the user clicks on a command button? In excel, its using the SUM function, but VBA doesnt have that. For instance, i want the sum of cells J10 to :J30....
-
May 6th, 2005, 09:25 AM
#2
Addicted Member
Re: an extreme newbie vba question
Set myRange = Worksheets("Sheet1").Range("A1:C10")
answer = Application.WorksheetFunction.Sum(myRange)
MsgBox answer
-
May 6th, 2005, 09:36 AM
#3
Thread Starter
Junior Member
Re: an extreme newbie vba question
I keep getting an error saying "Subscript out of range". any ideas?
-
May 7th, 2005, 11:01 PM
#4
Addicted Member
Re: an extreme newbie vba question
try this:
VB Code:
Option Explicit
Sub test()
Dim myRange As Range
Dim answer As String
Set myRange = Worksheets("Sheet1").Range("A1:C10")
answer = Application.WorksheetFunction.Sum(myRange)
MsgBox "The sum is " & Format(answer, "currency")
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|