View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Pete_UK Pete_UK is offline
external usenet poster
 
Posts: 8,856
Default HELP to correc this macro

It's better not to use Row as the count variable, given that this a reserved
word - make it myRow or some-such, and DIM it at the beginning of the macro.

Also, if you have selected cells on rows 1 to 3, then you will be trying to
set up an average for cells B-2, B-1 or B0 - such cells don't exist !!

Hope this helps.

Pete


"bioyyy" wrote in message
...
I got an error: (Run-time error '1004': Application-defined or
object-defined
error).

Thanks,

Sub Avg3Row()

Dim OutputRow As Integer

OutputRow = 1

For Row = Selection.Row To ActiveSheet.UsedRange.Rows.Count Step 30
Worksheets("Output").Cells(OutputRow, 1).Formula = "=average(Input!B" &
Row - 3 & ":B" & Row & ")"
OutputRow = OutputRow + 1
Next Row
End Sub