O.K. Let's say we have a column of numbers. There are blanks in the column,
but each blank has a filled cell above it and below it. For example:
1
2
3
4
5
6
7
8
8
11
Say we want to modify the macro to find each of the "special" blanks in the
column and deposit the formula in it:
Sub average_setter()
ad1 = ActiveCell.Offset(-1, 0).Address
ad2 = ActiveCell.Offset(1, 0).Address
s = ad1 & "," & ad2
ActiveCell.Formula = "=AVERAGE(" & s & ")"
End Sub
Sub main()
n = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To n
If IsEmpty(Cells(i, "A").Value) Then
Cells(i, "A").Select
Call average_setter
End If
Next
End Sub
The main macro loops down column A, looking for empty cells. When it finds
an empty, it Selects the cell and calls the average_setter macro to deposit
the formula.