To make it easier to code the function section
Sub InsertBeforeExperiment()
Dim Cel As Range
Dim lr as Long 'lr = # of Last used row
lr = Cells(Rows.Count, "A").End(xlUp).Row
Application.ScreenUpdating = False
For Each Cel in Range("A1:A" & LR)
If Cel= "Experiment" Then Cel.EntireRow.Insert
Next
Application.ScreenUpdating = True
End Sub
That code will insert an empty row before each "Experiment"
The start of the Function section of code is
Sub VBAXBySamT()
Dim Cel As Range
Dim X as Double
Dim Y As Double
Dim DataBlock As Variant
Dim arResults As Variant
Dim i As Long
'Starting point
Set Cel = Range("A2)"
Do While Cel.Row <>Rows.Count
X = Cel.Offset(1)
Y = Cel.Offset(2)
DataBlock = Range(Cel.Offset(4), Cel.End(xlDown).Offset(, 5))
Resize(arResults, UBound(DataBlock)) 'Give arResults the same number of "Rows" as DataBlock
'At this point in the code, DataBlock is an array of values 5 columns wide
'The first Row or the Array is = LBound(DataBlock), and the last row is =UBound(DataBlock)
'Values in the array are referenced like Cells in a Worksheet are; Value = Array(Row#, Column#)
'Loop thru this DataBlock
For i = LBound(DataBlock) to UBound(DataBlock)
arResults(i) = YourFunction(DataBlock(i), X, Y)
Next
'Put the results next to the Data on the worksheet
Cel.Offset(4, 5) = Results
Results = 0
DataBlock = 0
'New Start Point
Set Cel = Cel.End(xlDown).End(xlDown)
Loop
End Sub
Now you get to write the Function
Function YourFunction(DataRow As Variant, X As Double, Y As Double) As Double
Dim i As Long
Dim
Temp as Double
For i = Lbound(DataRow) To '. . . Your turn :)
'Temp = ???
'
'
'
This Function by Name = Temp
'Ex: assume the code is GetAnswer(DataRow As Variant, X As Double, Y As Double) As Double
'then that line is "GetAnswer = Temp"
End Function