My reports present their numerical data across the rows for columns D - AH
Using VBA macro, I need to insert a formula in each of the blank cells separating the ranges in order to average the range of cells above it by column. The ranges will vary in the number of rows between reports and can contain text. If needed I can add more blank rows between data sets.
D E F G etc....
4 4 5 2
2 5 n/a 4
_ _ _ _ <-- insert formulas in this row to average the range above in each column
3 2 4 5
2 n/a 4 3
9 3 3 2
_ _ _ _ <-- insert formulas in this row to average the range above in each column
and so on....
When all formulas are copied to the blank cells, each range then gets copied and pasted into its own worksheet; all ranges then begin with cell D2. (I have that code working). I need the formula to be copied with the data and work in the new worksheets.
The macro could simply fill the formula into all blank cells in the greater range D1-AH200 (preferred), or it could do it by columns, as I've tried with no success....
Any help will be greatly appreciated. Thanks.![]()
Sub insertFormula () Dim lngRow As Long For lngRow = 2 To Cells(Rows.Count, "D").End(xlUp).Row If (Range("D" & lngRow)) = "" And (Range("D" & lngRow + 1)) <> "" Then _ Range("D" & lngRow) . Formula = "=AVERAGE(Range("D" & lngRow + 1))" Next End Sub
Bookmarks