If I interpret you request correctly, you want to find the first and last
values in a column of numbers and sum them. Following is 2 macros. First one
does not take into account column headers. 2nd amendment assumes column
headers and starts at row 2 to find the first value.
Sub SumColumnNoHeaders()
Dim firstRow As Long
Dim lastRow As Long
Dim column_Name As String
Dim sumValue As Double
column_Name = "A"
With ActiveSheet
'Assuming no column headers
If .Cells(1, column_Name) = "" Then
firstRow = .Cells(1, column_Name).End(xlDown).Row
Else
firstRow = 1
End If
lastRow = .Cells(.Rows.Count, column_Name).End(xlUp).Row
End With
sumValue = WorksheetFunction.Sum(Range(Cells(firstRow, column_Name), _
Cells(lastRow, column_Name)))
'alternative code method
'sumValue = WorksheetFunction.Sum(Range(column_Name & firstRow & _
":" & column_Name & lastRow))
End Sub
If you have column headers then replace the If/Else/End If lines with the
following:-
'With column headers present
If .Cells(2, column_Name) = "" Then
firstRow = .Cells(2, column_Name).End(xlDown).Row
Else
firstRow = 2
End If
Regards,
OssieMac