![]() |
sum a range in VBA
What is the proper way to find the sum of a range in VBA. Here is what I
have Dim rRange as Range Dim iLastRow as as long Dim lSum as Long lLastRow = Cells(Rows.Count, "A").End(xlUp).Row Set rRange = Range ("A1:A" & lLastRow) 'Now I want to Sum rRange as they are all numbers? How do I do it. Say I want to add the value to a Variable called lSum? Thanks |
sum a range in VBA
Sub striker()
Dim rRange As Range Dim iLastRow As Long Dim lSum As Long lLastRow = Cells(Rows.Count, "A").End(xlUp).Row Set rRange = Range("A1:A" & lLastRow) MsgBox (Application.WorksheetFunction.Sum(rRange)) End Sub -- Gary''s Student - gsnu200838 "Striker" wrote: What is the proper way to find the sum of a range in VBA. Here is what I have Dim rRange as Range Dim iLastRow as as long Dim lSum as Long lLastRow = Cells(Rows.Count, "A").End(xlUp).Row Set rRange = Range ("A1:A" & lLastRow) 'Now I want to Sum rRange as they are all numbers? How do I do it. Say I want to add the value to a Variable called lSum? Thanks |
sum a range in VBA
lSum = Application.WorksheetFunction.Sum(rRange)
-- Regards, Nigel "Striker" wrote in message ... What is the proper way to find the sum of a range in VBA. Here is what I have Dim rRange as Range Dim iLastRow as as long Dim lSum as Long lLastRow = Cells(Rows.Count, "A").End(xlUp).Row Set rRange = Range ("A1:A" & lLastRow) 'Now I want to Sum rRange as they are all numbers? How do I do it. Say I want to add the value to a Variable called lSum? Thanks |
sum a range in VBA
lsum = application.sum(rrange)
or lsum = application.sum(range("a:a")) empty cells won't bother the =sum() Striker wrote: What is the proper way to find the sum of a range in VBA. Here is what I have Dim rRange as Range Dim iLastRow as as long Dim lSum as Long lLastRow = Cells(Rows.Count, "A").End(xlUp).Row Set rRange = Range ("A1:A" & lLastRow) 'Now I want to Sum rRange as they are all numbers? How do I do it. Say I want to add the value to a Variable called lSum? Thanks -- Dave Peterson |
sum a range in VBA
works fine
Thanks "Striker" wrote in message ... What is the proper way to find the sum of a range in VBA. Here is what I have Dim rRange as Range Dim iLastRow as as long Dim lSum as Long lLastRow = Cells(Rows.Count, "A").End(xlUp).Row Set rRange = Range ("A1:A" & lLastRow) 'Now I want to Sum rRange as they are all numbers? How do I do it. Say I want to add the value to a Variable called lSum? Thanks |
All times are GMT +1. The time now is 12:21 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com