![]() |
SUM Formula using code
Hi All,
How do you put a SUM Formula using VBA code in every end of rows where data rows are vary from time to time. I know it's : Range().Formula ="=Sum(Range)" But my point is, how can you anticipate data rows that vary from time to time and always put the SUM formula in the end of every data rows. Thanks in advance. sony |
SUM Formula using code
Hi Sony,
How about something like: Sub InsertTotals() Dim i As Long Dim r As Range Dim WS As Worksheet Set WS = ThisWorkbook.Worksheets(1) For i = 1 To 256 Set r = WS.Cells(65536, i).End(xlUp) If r.Row = 1 Then Exit For ' Assume no more data Set r = r.Offset(1, 0) r.Formula = "=SUM(R1C" & i & ":" & r.Offset(-1, 0).Address(, , xlR1C1) & ")" r.Font.Bold = True Next i End Sub HTH Peter Beach "Sony" wrote in message ... Hi All, How do you put a SUM Formula using VBA code in every end of rows where data rows are vary from time to time. I know it's : Range().Formula ="=Sum(Range)" But my point is, how can you anticipate data rows that vary from time to time and always put the SUM formula in the end of every data rows. Thanks in advance. sony |
All times are GMT +1. The time now is 04:18 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com