Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
sid sid is offline
external usenet poster
 
Posts: 14
Default Macro Sum Formula For a Variable Rang

Hi All,

Can some one please help me on how to fix code below to sum a variable
range? I am not sure if my sum formula is at fault or my whole logic got to
go.

Sub Question()
x = 0
c = 1

'To delete empty rows in the sheet
'
lastrow = ActiveSheet.UsedRange.Rows.count
Application.ScreenUpdating = False
For R = lastrow To 1 Step -1
If Application.WorksheetFunction.CountA(Rows(R)) = 0 _
Then Rows(R).Delete
c = c + 1
Next R

'To Add sum formulas on account rows


Do While x < c
x = x + 1
Dim BEGROW As Integer
Dim ENDROW As Integer
If Cells(x, 1) Like "Account:" Then
BEGROW = x + 1
End If

If Cells(x, 1) Like "Totals:" Then
Cells(x, 5).Select
ENDROW = ActiveCell.Row - 1
Selection.FormulaR1C1 = "=Sum(R"&BEGROW"C5:R"&ENDROW"C5)"
End If
Loop

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Macro Sum Formula For a Variable Rang

Selection.FormulaR1C1 = "=Sum(R"&BEGROW"C5:R"&ENDROW"C5)"
should be

Selection.FormulaR1C1 = "=Sum(R"& BEGROW & _
"C5:R" & ENDROW & "C5)"

would be a start.

--
Regards,
Tom Ogilvy


"Sid" wrote in message
...
Hi All,

Can some one please help me on how to fix code below to sum a variable
range? I am not sure if my sum formula is at fault or my whole logic got

to
go.

Sub Question()
x = 0
c = 1

'To delete empty rows in the sheet
'
lastrow = ActiveSheet.UsedRange.Rows.count
Application.ScreenUpdating = False
For R = lastrow To 1 Step -1
If Application.WorksheetFunction.CountA(Rows(R)) = 0 _
Then Rows(R).Delete
c = c + 1
Next R

'To Add sum formulas on account rows


Do While x < c
x = x + 1
Dim BEGROW As Integer
Dim ENDROW As Integer
If Cells(x, 1) Like "Account:" Then
BEGROW = x + 1
End If

If Cells(x, 1) Like "Totals:" Then
Cells(x, 5).Select
ENDROW = ActiveCell.Row - 1
Selection.FormulaR1C1 = "=Sum(R"&BEGROW"C5:R"&ENDROW"C5)"
End If
Loop



  #3   Report Post  
Posted to microsoft.public.excel.programming
sid sid is offline
external usenet poster
 
Posts: 14
Default Macro Sum Formula For a Variable Rang

Thank you Tom; Just What I needed.



"Sid" wrote:

Hi All,

Can some one please help me on how to fix code below to sum a variable
range? I am not sure if my sum formula is at fault or my whole logic got to
go.

Sub Question()
x = 0
c = 1

'To delete empty rows in the sheet
'
lastrow = ActiveSheet.UsedRange.Rows.count
Application.ScreenUpdating = False
For R = lastrow To 1 Step -1
If Application.WorksheetFunction.CountA(Rows(R)) = 0 _
Then Rows(R).Delete
c = c + 1
Next R

'To Add sum formulas on account rows


Do While x < c
x = x + 1
Dim BEGROW As Integer
Dim ENDROW As Integer
If Cells(x, 1) Like "Account:" Then
BEGROW = x + 1
End If

If Cells(x, 1) Like "Totals:" Then
Cells(x, 5).Select
ENDROW = ActiveCell.Row - 1
Selection.FormulaR1C1 = "=Sum(R"&BEGROW"C5:R"&ENDROW"C5)"
End If
Loop

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
In WORKDAY function, how to exclude multiple/variable holiday rang Harold Shea Excel Discussion (Misc queries) 4 August 3rd 09 06:53 PM
Macro - Formula RC[?] with ? being a variable number steven.holloway Excel Discussion (Misc queries) 5 July 18th 08 10:07 AM
Rang reference incrementing by more than one on formula drag Kai Cunningham[_2_] Excel Worksheet Functions 2 April 3rd 08 09:20 PM
Help with macro formula and variable Huge project Excel Worksheet Functions 0 December 28th 04 01:27 AM
entering formula using variable in Excel Macro doc-s Excel Programming 1 August 18th 04 08:27 PM


All times are GMT +1. The time now is 01:20 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"