Impartial Derivative
New Member
- Joined
- Jun 15, 2011
- Messages
- 1
For my research I must import tab delimited data and then create a macro in order to calculate several calculations relating the data. I have written a macro and received help on several parts of it but am now stuck again on how to address some issues with my code. In particular I am looking to calculate the net distance traveled by a particle. In my Excel document the data reports multiple trajectories for multiple particles and there are spaces between the data for each particle. For my net calculation I need to use the equation Sqrt((x2-x1)^2+(y2-y1)^2) but y1 and x1 need to be set as the first entry for each trajectory. It could be frame 0 or frame 4 but I need every calculation to reference that first entry. I have included my spreadsheet with formulas so you can see what I'm doing more clearly. The spreadsheet shows all of the calculations I am looking for the macro to do, I just can't seem to sort out the syntax to get this all done. Sorry if this isn't very clear it's rather confusing and hard to explain so feel free to ask questions.
Here is my macro so far:
P.S. If you'd like to pm your email I would gladly email you my workbook to make things easier.
Here is my macro so far:
Code:
Sub AverageDistance()
Dim M As Long
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
M = Application.WorksheetFunction.Max(Range("A:A"))
With Range("G3:G" & LR)
.FormulaR1C1 = "=IF(ISNUMBER(RC1), SQRT(((R[1]C2-RC2)^2)+((R[1]C3-RC3)^2)), """")"
.Value = .Value
End With
'With
'With Range("H2:H" & LR)
'.FormulaR1C1 = "=IF(ISNUMBER(RC1),("
Range("G1:J1").Value = [{"Ave Dist","Ave Sum","Net Dist","Net Sum"}]
Range("Q1:U1").Value = [{"Frame","Ave Dist","Ave Sum","Net Dist","Net Sum"}]
Range("Q2") = 0
Range("Q3").Resize(M).FormulaR1C1 = "=R[-1]C + 1"
Range("R2:R" & M + 2).FormulaR1C1 = "=AVERAGEIF(R1C1:R" & LR & "C1, RC[-1], R1C7:R" & LR & "C7)"
'Range("S2:S" & M + 2).FormulaR1C1 = "=AVERAGEIF(R1C1:S" & LR & "C1,RC[-1]"
End Sub
P.S. If you'd like to pm your email I would gladly email you my workbook to make things easier.