PDA

View Full Version : Autosum unfixed range above



satyen
10-13-2011, 04:03 AM
Hello.

I am having trouble figuring out the code to calculate the autosum the above range. There is not set range , row or column as this will change from sheet to sheet.

Please can someone help.

I found this as it similar to what I am looking for- but this looks at the fixed column D. Not what I am looking for.

Sub SumMyRange()
Range("D65536").End(xlUp).Offset(1, 0) = _
"=Sum($D:" & Range("D65536").End(xlUp).Address & ")"
End Sub

Please can someone help. Thank you

Bob Phillips
10-13-2011, 04:16 AM
Sub SumMyRange()
With ActiveCell

.Formula = "=Sum(" & Range(.Offset(-.Row + 1, 0), .Offset(-1, 0)).Address & ")"
End With
End Sub

satyen
10-13-2011, 04:46 AM
thank you. Sorry my fault, as I didn't explain properly. There are headings and it should only go up as far as these headings and sum everything below the heading. Does this make sense?

Bob Phillips
10-13-2011, 05:55 AM
Are the headings always row 1 or could they be in any row.

satyen
10-13-2011, 06:14 AM
Any row.

satyen
10-13-2011, 06:39 AM
Found one way of doing this. But with this I have to have a selected column and the column could change.

This code is from the Ozgrid.com forum

Sub AutoSum()

For Each NumRange In Columns("D").SpecialCells(xlConstants, xlNumbers).Areas
SumAddr = NumRange.Address(False, False)
NumRange.Offset(NumRange.Count, 0).Resize(1, 1).Formula = "=SUM(" & SumAddr & ")"
c = NumRange.Count
Next NumRange

NoData:

End Sub

satyen
10-13-2011, 06:42 AM
Also just seen it's subtotalling all the above tables on that sheet, which I do not want it to do.

Bob Phillips
10-13-2011, 06:49 AM
You've lost me now.