Help needed to insert rows with average and standard deviation after specific text

mehndi89

New Member
Joined
Sep 25, 2013
Messages
1
Hi,

I have a spreadsheet with around 900 rows and lots of sets of duplicates that I need to separate from each other and analyze. I need a macro to insert 3 blank rows after every set of 9 that can be identified by the text in the last row of column A which will include the words "Site 9".

Then I want to copy the value of the last row column A into the first inserted row and include the averages of all the values above in columns B to I.

In the second blank row I want to include the standard deviation.

The third inserted row should be left blank.

Here is a glimpse of how it looks:

Before macro
:

A
B
Stage Label
Total Cells
A01 : Site 1
261
A01 : Site 2
177
A01 : Site 3
46
A01 : Site 4
66
A01 : Site 5
118
A01 : Site 6
123
A01 : Site 7
39
A01 : Site 8
23
A01 : Site 9
93
A02 : Site 1
472
A02 : Site 2
370
A02 : Site 3
398
A02 : Site 4
296
A02 : Site 5
266
A02 : Site 6
320
A02 : Site 7
153
A02 : Site 8
164
A02 : Site 9
362

<tbody>
</tbody>

After macro:

A
B
Stage Label
Total Cells
A01 : Site 1
261
A01 : Site 2
177
A01 : Site 3
46
A01 : Site 4
66
A01 : Site 5
118
A01 : Site 6
123
A01 : Site 7
39
A01 : Site 8
23
A01 : Site 9
93
A01 average
105.11111
A01 std dev
76.025398
A02 : Site 1
472
A02 : Site 2
370
A02 : Site 3
398
A02 : Site 4
296
A02 : Site 5
266
A02 : Site 6
320
A02 : Site 7
153
A02 : Site 8
164
A02 : Site 9
362
A02 average
311.22222
A02 std dev
105.16389

<tbody>
</tbody>

Right now I only have a macro for inserting rows as shown:

Sub Insert3Rows()
Dim c As Range
For Each c In Range("A2:A10000")
If c.Value Like "*Site 9*" Then
c.Offset(1, 0).EntireRow.Insert
c.Offset(1, 0).EntireRow.Insert
c.Offset(1, 0).EntireRow.Insert
End If
Next c
End Sub

Is there a simple way to combine everything so I can insert the blank rows, label column a and calculate average & standard deviation?
 
Last edited:

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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
Back
Top