View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
achidsey achidsey is offline
external usenet poster
 
Posts: 100
Default AutoSum macro that doesn't include headings

Excel Experts,

I wrote the below code which seems to be effective in putting an autosum
formula below a column of numbers such as this one. I select the cell below
the numbers and run the macro.

A B
1
2 100
3 200
4 50
5

However, how can I modify it so if I have a heading on my column of numbers,
or even two or three cells with text above my number column, the code will
start the range for the autosum with the top numerical cell of my column.

Thanks,
Alan


Sub AutoSum()

Dim SumCell As Range
Dim FirstCell As Range
Dim LastCell As Range

Set SumCell = Selection

Set FirstCell = SumCell.Offset(-1).End(xlUp)

Set LastCell = SumCell.Offset(-1)

With SumCell
.FormulaR1C1 = "=sum(" & FirstCell.Address(False, False, xlR1C1, _
RelativeTo:=.Item(1)) & ":" & LastCell.Address(False, False, xlR1C1, _
RelativeTo:=.Item(1)) & ")"
End With

End Sub