R
ryguy7272
Mid afternoon; got into the office early and still not fully awake here. I
am trying to loop through all sheets and fine the average for numbers in a
range, which always starts in J2 (has a header) and goes down a variable
number of rows. I want to enter the average in Cell K1. This is what I have
so far.
Sub Aver()
Dim lastrow As Long
For Each sh In Worksheets
If (sh.Name) <> "Summary Sheet" And (sh.Name) <> "Alpha" And (sh.Name)
<> "PSA Time Interval" And (sh.Name) <> "Summary" Then
sh.Activate
With sh
lastrow = .Cells(.Rows.Count, "J").End(xlUp).Row
.Cells(lastrow, "K").Activate
'ActiveCell.Offset(0, 0).Select
Selection.End(xlUp).Select
ActiveCell.FormulaR1C1 = "=average(r2c" & lastrow
End With
End If
Next sh
End Sub
My macro is trying to calculate the average in column K, but I want to base
the average on Column J. Please help.
TIA,
Ryan---
am trying to loop through all sheets and fine the average for numbers in a
range, which always starts in J2 (has a header) and goes down a variable
number of rows. I want to enter the average in Cell K1. This is what I have
so far.
Sub Aver()
Dim lastrow As Long
For Each sh In Worksheets
If (sh.Name) <> "Summary Sheet" And (sh.Name) <> "Alpha" And (sh.Name)
<> "PSA Time Interval" And (sh.Name) <> "Summary" Then
sh.Activate
With sh
lastrow = .Cells(.Rows.Count, "J").End(xlUp).Row
.Cells(lastrow, "K").Activate
'ActiveCell.Offset(0, 0).Select
Selection.End(xlUp).Select
ActiveCell.FormulaR1C1 = "=average(r2c" & lastrow
End With
End If
Next sh
End Sub
My macro is trying to calculate the average in column K, but I want to base
the average on Column J. Please help.
TIA,
Ryan---