Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
formula or vba code Nader Excel Worksheet Functions 14 August 16th 06 10:54 AM
formula code nobbyknownowt Excel Discussion (Misc queries) 5 August 10th 06 05:40 PM
formula or code Monty Excel Worksheet Functions 10 January 10th 05 09:06 AM
Formula or code Jim[_15_] Excel Programming 0 July 9th 03 05:51 PM
Formula or code John Gittins Excel Programming 0 July 9th 03 04:16 PM


All times are GMT +1. The time now is 05:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"