PDA

View Full Version : A variable SUM formula in excel



bbuk9999
05-12-2016, 07:56 AM
Hi all, does anyone know how to provide a variable SUM formula. For example: SUM(A1:Variable), This variable can be any range like SUM(A1:K10) or SUM(A1:N20). Thanks in advance.

Paul_Hossler
05-12-2016, 08:01 AM
If this is the same question that you asked here:

http://www.vbaexpress.com/forum/showthread.php?55993-How-to-generate-Sum-formula-in-excel

the answers would probably be the same unless you can tell us what was wrong with them

bbuk9999
05-12-2016, 08:08 AM
thanks Paul, The variable range depends on a variable that can be inserted using VBA code.

Paul_Hossler
05-12-2016, 10:09 AM
Option Explicit

Sub test()
Dim r1 As Range, r2 As Range
Set r1 = Range("A1")
Set r2 = Range("E10")

MsgBox Application.WorksheetFunction.Sum(Range(r1, r2))

End Sub