menos
02-14-2011, 05:18 AM
Skin conductance level fluctuates in waves. I would like to count the number of peaks that rose 2 or more units in 30 seconds. In col A I have SCL (skin conductance level). Col B shows every SCL reading that was a rise of 2 or more units in 30seconds (else 0).
However, this flags multiple rises per peak because many peaks rise much more than 2 in 30s. I am only interested in counting no. of peaks meeting the criteria, so I want to create a new col that ignores any rises after the first, until it reaches the peak. I have some code that I think will more or less do it, but I don’t know vba well enough to correctly define and set my variables and to use terms correctly. Could anyone help with this?
Thanks!
Dim SCLrange As Range
Dim HFrange As Range
Dim HFcell As Range
Dim SCLcell As Range
'HFrange is col B
'SCLrange is the cells in col A which rise after the first rise in each peak
For Each HFcell In HFrange
If HFcell > 0 Then
'need to define SCLrange as the cells after the first rise where SCL continues to rise
For Each SCLcell In SCLrange
If SCLcell.Value - SCLcell.Offset(-1, 0).Value < 0 Then
HFcell.Offset(0, 1).Value = HFcell.Value 'if reached the peak of the SCL rise then copy the value in row x, column b to row x, column c, and then look at the next value >0 in col b
'[go to the next HFcell >0]
If SCLcell.Value - SCLcell.Offset(-1, 0).Value >= 2 Then
HFcell.Offset(0, 1).Value = 0
End If 'if SCLcell.Value - SCLcell.Offset(-1, 0).Value is between 0 and 2 then just need to go to next SCLcell so haven't specified this
Next SCLcell
End If
Next HFcell
However, this flags multiple rises per peak because many peaks rise much more than 2 in 30s. I am only interested in counting no. of peaks meeting the criteria, so I want to create a new col that ignores any rises after the first, until it reaches the peak. I have some code that I think will more or less do it, but I don’t know vba well enough to correctly define and set my variables and to use terms correctly. Could anyone help with this?
Thanks!
Dim SCLrange As Range
Dim HFrange As Range
Dim HFcell As Range
Dim SCLcell As Range
'HFrange is col B
'SCLrange is the cells in col A which rise after the first rise in each peak
For Each HFcell In HFrange
If HFcell > 0 Then
'need to define SCLrange as the cells after the first rise where SCL continues to rise
For Each SCLcell In SCLrange
If SCLcell.Value - SCLcell.Offset(-1, 0).Value < 0 Then
HFcell.Offset(0, 1).Value = HFcell.Value 'if reached the peak of the SCL rise then copy the value in row x, column b to row x, column c, and then look at the next value >0 in col b
'[go to the next HFcell >0]
If SCLcell.Value - SCLcell.Offset(-1, 0).Value >= 2 Then
HFcell.Offset(0, 1).Value = 0
End If 'if SCLcell.Value - SCLcell.Offset(-1, 0).Value is between 0 and 2 then just need to go to next SCLcell so haven't specified this
Next SCLcell
End If
Next HFcell