HELP to correc this macro

B

bioyyy

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
 
P

Pete_UK

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top