Another VBA question (I'm on fire lately) As the title says, I am trying to sum a column that can can be of a variable length and then stick that sum in cell F3, but I am running into a an "application or object defined error.
Here's my code:
Dim last As Range, sum As Variant
ActiveSheet.Range("M8").Select
Set last = Selection.End(xlDown)
With Worksheets("Data")
sum = WorksheetFunction.sum(.Range("M8:M" & last))
End With
Range("F:3") = sum
Use this function to robustly count the non-empty cells down from a cell.
Using your method, last needs to be a Long to which you assign the row number.
You could also do it a little more efficiently, by using
and not using the Select.
There is a non VBA way. In cell
F3
type the following:NB - this assumes the only content of column M are the numbers you'd like to sum