repeat row addition with formulas

Jrenville

New Member
Joined
Jan 30, 2018
Messages
2
My data always looks like the below. Title changes every after 5th line
I need to add 4 rows with Min,Max,Range, and average for each new title.

TitleYZABCDF
S01 811A2.5108.81.6134.6-7434.8811
S01 811A5120.61.6838.9-81.539811
S01 811A7.594.11.6131-6331.1811
S01 811A10100.11.6233.9-6634.1811
S01 811A12.5106.41.6436.9-69.437.1811
S02 753A2.5104.81.6332.5-72.132.7753
S02 753A5132.91.6537-95.737.2753
S02 753A7.5107.81.6438.3-69.438.5753
S02 753A10122.51.6535.8-86.536753
S02 753A12.5107.51.6536.6-70.736.9753
S03 767A2.5121.81.6336.9-84.737.1767
S03 767A51031.6333.5-69.333.8767
S03 767A7.51081.6332.2-75.732.3767
S03 767A1099.91.6231.4-68.331.7767
S03 767A12.51001.6232.7-67.132.9767

<tbody>
</tbody>

Need to do this:
TitleYZABCDF
S01 811A2.5108.81.6134.6-7434.8811
S01 811A5120.61.6838.9-81.539811
S01 811A7.594.11.6131-6331.1811
S01 811A10100.11.6233.9-6634.1811
S01 811A12.5106.41.6436.9-69.437.1811
min  1.6131 31.1 
max  1.6838.9 39 
range  0.077.9 7.9 
average  1.63235.06 35.22 
S02 753A2.5104.81.6332.5-72.132.7753
S02 753A5132.91.6537-95.737.2753
S02 753A7.5107.81.6438.3-69.438.5753
S02 753A10122.51.6535.8-86.536753
S02 753A12.5107.51.6536.6-70.736.9753

<tbody>
</tbody>


I have this code that I recorded. It works when I put on the right row. I just want it to repeat after 5 lines until there are empty cells because I do not have a specific number of samples: I'm just not really sure how to get it to repeat and stop.

Code:
Sub Insert_Rows()
'
' Insert_Rows Macro
' Inserts rows, adds min,max,range,average
'


'
    Rows("7:7").Select
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("A7").Select
    ActiveCell.FormulaR1C1 = "min"
    Range("A8").Select
    ActiveCell.FormulaR1C1 = "max"
    Range("A9").Select
    ActiveCell.FormulaR1C1 = "range"
    Range("A10").Select
    ActiveCell.FormulaR1C1 = "average"
    Range("D7").Select
    ActiveCell.FormulaR1C1 = "=MIN(R[-5]C:R[-1]C)"
    Range("D8").Select
    ActiveCell.FormulaR1C1 = "=MAX(R[-6]C:R[-2]C)"
    Range("D9").Select
    ActiveCell.FormulaR1C1 = "=R[-1]C-R[-2]C"
    Range("D10").Select
    ActiveCell.FormulaR1C1 = "=AVERAGE(R[-8]C:R[-4]C)"
    Range("D7:D10").Select
    Selection.Copy
    Range("E7").Select
    ActiveSheet.Paste
    Range("G7").Select
    ActiveSheet.Paste
End Sub

Thanks in advance
Jason
 
Last edited by a moderator:

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Hi & welcome to the board.
How about
Code:
Sub Insert_Rows()
    
   Dim Cnt As Long
   
   For Cnt = Range("A" & Rows.Count).End(xlUp).Row To 2 Step -5
      Rows(Cnt + 1).Resize(4).Insert
      Range("A" & Cnt + 1).Resize(4).Value = Application.Transpose(Array("Min", "Max", "Range", "Average"))
      Range("D" & Cnt + 1).Resize(, 4).FormulaR1C1 = "=MIN(R[-5]C:R[-1]C)"
      Range("D" & Cnt + 2).Resize(, 4).FormulaR1C1 = "=MAX(R[-6]C:R[-2]C)"
      Range("D" & Cnt + 3).Resize(, 4).FormulaR1C1 = "=R[-1]C-R[-2]C"
      Range("D" & Cnt + 4).Resize(, 4).FormulaR1C1 = "=AVERAGE(R[-8]C:R[-4]C)"
      Range("F" & Cnt + 1).Resize(4).ClearContents
   Next Cnt
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,674
Messages
6,126,149
Members
449,294
Latest member
Jitesh_Sharma

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