Skip to content

Instantly share code, notes, and snippets.

@stevehenderson
Last active December 17, 2015 09:29
Show Gist options
  • Save stevehenderson/5587589 to your computer and use it in GitHub Desktop.
Save stevehenderson/5587589 to your computer and use it in GitHub Desktop.
VBA Code to sum Range on a specified given sheetName and the coordinates of upper left and lower range corners.
'SumRangeOnSheet(sheetName, r0, c0, r1, c1 As Integer)
'
'Returns the sum of a range specied by UL point (r0, c0) and LR cell (r1,c0)
'on a worksheet specified by sheetName
'
Public Function SumRangeOnSheet(sheetName As String, r0 As Integer, c0 As Integer, r1 As Integer, c1 As Integer)
Dim aRange As Range
Set aRange = ActiveWorkbook.Sheets(sheetName).Range(ActiveWorkbook.Sheets(sheetName).Cells(r0, c0), ActiveWorkbook.Sheets(sheetName).Cells(lastRow, c0))
SumRangeOnSheet = Application.WorksheetFunction.Sum(aRange)
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment