Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 21
Default Input calculation in specified rows and columns

Sub Inspectthis()

Dim F As String
Dim I As Integer
Dim PrevRow As Long
Dim R As Long
Dim Rng As Range
Dim RngEnd As Range
Dim SumArray As Variant
Dim Wks As Worksheet

Set Wks = Worksheets("Sheet1")

SumArray = Array("O", "R", "U", "X", "AA", "AD", "AG")

Set Rng = Wks.Range("A2")
Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp)
Set Rng = IIf(RngEnd.Row < Rng.Row, Rng, Wks.Range(Rng, RngEnd))

PrevRow = 2

For R = 2 To Rng.Rows.Count
If Rng.Item(R) = "Renovation" Then
For I = 0 To UBound(SumArray)
F = "=SUM(" & SumArray(I) & PrevRow & ":" & SumArray(I) & R & ")"
Wks.Cells(R + 1, SumArray(I)).Formula = F
Next I
PrevRow = R
End If
Next R

End Sub


The macro above will inspect every row in Column A for the text Renovation.
When the text Renovation is found the average formula, =Average(Range:Range)
will be inserted in the same row in Columns O, R, U, X, AA, AD, AG so that
all the rows above the formula with numbers will be included in the
calculation just as if I clicked the AutoSum icon and set it to average. The
problem I am having with macro above is that the formula range seems to be
grabbing into the calculation 1 extra row above what it should be including
in the formula which is messing up the computation. Can you help me fix this
macro so that it stops grabbing the 1 extra row above so the calculation is
correct?
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 21
Default SOLVED: Input calculation in specified rows and columns

Please ignore this post. I mistakenly posted in the wrong forum. I will
repost in correct forum. Please ignore this post. Thank you.

"Buddy" wrote:

Sub Inspectthis()

Dim F As String
Dim I As Integer
Dim PrevRow As Long
Dim R As Long
Dim Rng As Range
Dim RngEnd As Range
Dim SumArray As Variant
Dim Wks As Worksheet

Set Wks = Worksheets("Sheet1")

SumArray = Array("O", "R", "U", "X", "AA", "AD", "AG")

Set Rng = Wks.Range("A2")
Set RngEnd = Wks.Cells(Rows.Count, Rng.Column).End(xlUp)
Set Rng = IIf(RngEnd.Row < Rng.Row, Rng, Wks.Range(Rng, RngEnd))

PrevRow = 2

For R = 2 To Rng.Rows.Count
If Rng.Item(R) = "Renovation" Then
For I = 0 To UBound(SumArray)
F = "=SUM(" & SumArray(I) & PrevRow & ":" & SumArray(I) & R & ")"
Wks.Cells(R + 1, SumArray(I)).Formula = F
Next I
PrevRow = R
End If
Next R

End Sub


The macro above will inspect every row in Column A for the text Renovation.
When the text Renovation is found the average formula, =Average(Range:Range)
will be inserted in the same row in Columns O, R, U, X, AA, AD, AG so that
all the rows above the formula with numbers will be included in the
calculation just as if I clicked the AutoSum icon and set it to average. The
problem I am having with macro above is that the formula range seems to be
grabbing into the calculation 1 extra row above what it should be including
in the formula which is messing up the computation. Can you help me fix this
macro so that it stops grabbing the 1 extra row above so the calculation is
correct?

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
repeat calculation for different combination of input? Oligo Excel Discussion (Misc queries) 11 March 17th 09 08:23 PM
Manual Input/Calculation in Same Cell Jean9 Excel Discussion (Misc queries) 3 November 8th 07 04:00 PM
Excel 2003 - change columns to rows and rows to columns Trish Excel Discussion (Misc queries) 0 August 17th 07 02:22 AM
calculation with hours and minutes - input of negative values MichaelMichael Excel Discussion (Misc queries) 2 July 10th 06 06:31 PM
how to input a calculation in excel to find the geometric mean student1 Excel Worksheet Functions 3 July 7th 05 02:21 PM


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

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

About Us

"It's about Microsoft Excel"