Data analysis with a Tab Delimited Excel Document

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:
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.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,224,503
Messages
6,179,136
Members
452,890
Latest member
Nikhil Ramesh

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