Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am attempting to perform a data analysis using data collected through a parallel port. I have a macro written that does not do what it is supposed to do. First, the data that I am taking in comes in three columns, (time, potential, and pressure). The macro (when working properly) should truncate the pressures down to just digits, no decimals. then it should average all of the potential data points with a particular pressure value. then, it should repeat this until it has gone through the whole data set. Unfortunantly, this macro will truncate the pressures, but then it returns only the last value of the potential that it reads, it does no averaging and reads only one data point. Any help on this would be appriciated. the macro is below.
'
' Average_Finder Macro
' Macro Created by Connor English
'
'
Sub Average_Finder()
max_cycle = 300Rem Set Columns for the data
New_P = 1
Avg_P = 2
Avg_V = 3
Num_Samp = 4
Volts = -1 - New_P
cycle = 0Rem Extra variables Needed
Tally = 0
Tally_Num = 0
Rem Truncates the first term to the correct column and then finds the exact value
first_term = ActiveCell.Offset(0, 0).Range("A1").Value
quick_tally = 0
While (cycle max_cycle)
Rem Finds the actual value
ActiveCell.Offset(0, New_P).Range("A1").Select
ActiveCell.FormulaR1C1 = "=TRUNC(RC[-1], 0)"
ActiveCell.Offset(0, 0).Range("A1").Select
Selection.Copy
ActiveCell.Offset(0, 0).Range("A1").Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=FalseRem Checks to see if at the end of the sequence of values
ActiveCell.Offset(1, -New_P).Range("A1").Select
If (ActiveCell.Offset(0, 0).Range("A1").Value first_term) Then
quick_tally = cycle
cycle = max_cycle
End If
cycle = cycle + 1
Wend
cycle = 0
Rem Resets at the beginning of the dataset
ActiveCell.Offset(-quick_tally - 1, New_P).Range("A1").SelectRem While Loop keeps cycling until max cycle has been reached or until the end of the data has been found
While (cycle max_cycle)
Rem Checks to see if the next value for the pressure is the same. If yes, then
Rem Selects the volts term, adds it to the sub-total for that torr group
Rem and tally's the number of data points in that torr group
If (ActiveCell.Offset(0, 0).Range("A1").Value = ActiveCell.Offset(1, 0).Value) Then
ActiveCell.Offset(0, Volts).Range("A1").Select
Torr_Group = Selection
Tally = Tally + Torr_Group
Tally_Num = Tally_Num + 1
ActiveCell.Offset(0, -Volts).Range("A1").Select
Rem Checks to see if the next value is greater than the current torr group. If yes, then
Rem Does the same thing as the previous group (I know, Excess coding)
Rem Finally, it resets the tally number and the torr group values and prints them.
ElseIf (ActiveCell.Offset(0, 0).Range("A1").Value ActiveCell.Offset(1, 0).Value) Then
ActiveCell.Offset(0, Volts).Range("A1").Select
Torr_Group = Selection
Tally = Tally + Torr_Group
Tally_Num = Tally_Num + 1
Rem Place the average voltage
ActiveCell.Offset(0, -Volts + Avg_V).Range("A1").Select
ActiveCell.Offset(0, 0).Range("A1").Value = Tally / Tally_Num
Rem Place the Torr value and the number of Torr samples
ActiveCell.Offset(0, -Avg_V).Range("A1").Select
temp_grab = Selection
ActiveCell.Offset(0, Avg_P).Range("A1").Value = temp_grab
ActiveCell.Offset(0, Num_Samp).Range("A1").Value = Tally_Num
Tally = 0
Tally_Num = 0Rem If the next Value for Torr is less than the current, then the process ends
Rem It still tabulates the final average.
Else
cycle = max_cycle
ActiveCell.Offset(0, Volts).Range("A1").Select
Torr_Group = Selection
Tally = Tally + Torr_Group
Tally_Num = Tally_Num + 1
Rem Place the average voltage
ActiveCell.Offset(0, -Volts + Avg_V).Range("A1").Select
ActiveCell.Offset(0, 0).Range("A1").Value = Tally / Tally_Num
Rem Place the Torr value and the number of Torr samples
ActiveCell.Offset(0, -Avg_V).Range("A1").Select
temp_grab = Selection
ActiveCell.Offset(0, Avg_P).Range("A1").Value = temp_grab
ActiveCell.Offset(0, Num_Samp).Range("A1").Value = Tally_Num
End IfRem Move down to the next value and add one more to the cycle
ActiveCell.Offset(1, 0).Range("A1").Select
cycle = cycle + 1
Rem End of the while loop
Wend
ActiveCell.Offset(0, 4).Range("A1").Value = "DONE"End Sub
Thanks for any help provided.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |