I keep on getting an "object variable not set" error with this code. I want to offset the startcell cell address to take the average of a corresponding column. However, vba tries to offset the value of the startcell, rather than the cell address. It would be great if someone can offer me some guidance. Thanks!
Sub Macro1()
Dim i As Integer
Dim rowcount As Integer
Dim startcell As Range
startcell = ActiveSheet.Cells(2, 3).Address(False, False)
rowcount = Range("C2", Range("C2").End(xlDown)).Count
For i = 1 To rowcount
If Not Cells(i, 3).Value = Cells(i + 1, 3).Value Then
startcell.Offset(0, 11).Value = Application.WorksheetFunction.Average( _
Range(startcell.Offset(0, 8), Cells(i, 11)))
startcell = ActiveSheet.Cells(i + 1, 3).Address(False, False)
End If
Next i
End Sub
Setfor the range variable startcell.Set startcell = ActiveSheet.Cells(2, 3)Set startcell = ActiveSheet.Range(Cells(2, 3), Cells(2, 3))