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?
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,675
Messages
5,838,718
Members
430,566
Latest member
ChanchalSingh

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