findblank cell in column, insert formula then next blank cell and so on

ronjo

New Member
Joined
Jul 14, 2010
Messages
17
I've searched to no avail. I have a sheet consisting of 7 columns and a variable number of rows. The rows are split at random intervals with an empty row.
I wish to find each blank cell in turn in column G and insert an average function for the range of cells immediately above the blank cell. The range will contain some cells with text.
Please can anyone help?
 

Some videos you may like

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

ScottD

Board Regular
Joined
Sep 8, 2008
Messages
67
Try this:

Sub avg_blank()
lr = Range("g" & Rows.Count).End(xlUp).Row
astart = 5 'change 5 to first row of data
For i = 5 To lr + 1 'change 5 to first row of data
If Range("g" & i).Value = "" Then
aend = i - 1
Formu = "=average(g" & astart & ":g" & aend & ")"
Range("g" & i).Value = Formu
astart = i + 1
End If
Next i
End Sub
 

ronjo

New Member
Joined
Jul 14, 2010
Messages
17
What can I say - Thank you very much ScottD it is exactly what I was going round in circles trying to solve and works perfectly. Thanks again and kind regards.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,481
Messages
5,601,918
Members
414,482
Latest member
morkar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top