VBA to Sum data above Header row

kstrain

New Member
Joined
Sep 20, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
I am trying to do a sum in cell H1, which is above my header row (row 2). I want it to sum everything in column H to the last row (which could change each time the report is ran). I need it to exclude the header in cell H2.

Any help appreciated.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Do it your function...
Follow example print below .
VBA Code:
Public Function kStrain(pRng As Range) As Double

Dim xColIndex As Integer
Dim xRowIndex As Integer
Dim ws As Worksheet

Set pRng = pRng.Columns(1)
Set ws = pRng.Parent

xIndex = pRng.Column
    xRowIndex = ws.Cells(Rows.Count, xIndex).End(xlUp).Row

Set pRng = ws.Range(ws.Cells(3, xIndex), ws.Cells(xRowIndex, xIndex))
    kStrain = Application.WorksheetFunction.Sum(pRng)

End Function

1667578372138.png
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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