Forum Discussion
Autosum
- Nov 30, 2021
Josh_Waldner in its simplest form, it would be something like below :-
Sub MyAutoSum() Application.CutCopyMode = False Dim rngSumRange As Range Set rngSumRange = Range(ActiveCell.Offset(-1, 0), ActiveCell.Offset(-1, 0).End(xlUp)) ActiveCell.Formula = "=SUM(" & rngSumRange.Address & ")" End SubThough it is not as intelligent as autosum button
Example, below column, autosum button sums as 123, but above simple macro sums as zero. I am not sure of what all behaviour and checks are there in autosum button, but if one can list, then perhaps with more sophisticated macro, one can emulate it in VBA.
-123 abc 123
Josh_Waldner in its simplest form, it would be something like below :-
Sub MyAutoSum()
Application.CutCopyMode = False
Dim rngSumRange As Range
Set rngSumRange = Range(ActiveCell.Offset(-1, 0), ActiveCell.Offset(-1, 0).End(xlUp))
ActiveCell.Formula = "=SUM(" & rngSumRange.Address & ")"
End Sub
Though it is not as intelligent as autosum button
Example, below column, autosum button sums as 123, but above simple macro sums as zero. I am not sure of what all behaviour and checks are there in autosum button, but if one can list, then perhaps with more sophisticated macro, one can emulate it in VBA.
| -123 |
| abc |
| 123 |