VB Script For Peak Detection
VB Script For Peak Detection
Dim X
Dim lngRow As Long
Dim lngDestRow As Long
Dim lngSize As Long
X = Range([A1], Cells(Rows.Count, "B").End(xlUp))
lngDestRow = UBound(X, 1) + 1
ActiveSheet.Cells(1, 17).Value = "Rows = " & lngDestRow
X = Range([J2], Cells(Rows.Count, "K").End(xlUp))
ActiveSheet.Cells(1, "D").Value = "Peak kN)"
For lngRow = 1 To UBound(X, 1)
ActiveSheet.Cells(lngDestRow, "A").Value = X(lngRow, 1)
ActiveSheet.Cells(lngDestRow, "D").Value = X(lngRow, 2)
lngDestRow = lngDestRow + 1
Next lngRow
'
Columns("A:D").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatterLinesNoMarkers
ActiveChart.SetSourceData Source:=Range("$A:$D")
ActiveChart.SeriesCollection(3).Select
With Selection
.MarkerStyle = xlMarkerStyleX
.MarkerSize = 5
'.MarkerBackgroundColorIndex = xlColorIndexNone
'.MarkerForegroundColorIndex = xlColorIndexAutomatic
End With
Selection.MarkerStyle = 5
Selection.Format.Line.Visible = msoFalse
End Sub
Sub NewGraph()
Const Threshold = 10
Dim
Dim
Dim
Dim
Dim
Dim
Dim
Dim
Dim
Dim
X
Y
lngRow As Long
lngCnt As Long
Chr As ChartObject
lngPeak As Long
lngTrough As Long
Flag As Boolean
Peak, Trough As Double
lastRow As Long
Flag = False
'Remove header row if present
If ActiveSheet.Cells(2, 1).Value = "(mm)" Then
Range([A2], [B2]).Delete Shift:=xlUp
End If
'
'
'
/
lngCnt = lngCnt + 1
End If
Flag = False
'
'
'
End If
End If
lngCnt = lngCnt + 1
Y(1, lngCnt) = X(lngRow, 1)
Y(2, lngCnt) = X(lngRow, 2)
End If
End If
Next lngRow
DrawGraph
'
'
'
'
'
'
'
'
'
With .SeriesCollection.NewSeries
.XValues = Application.Index(Application.Transpose(Y), 0, 1)
.Values = Application.Index(Application.Transpose(Y), 0, 2)
End With
.ChartType = xlXYScatter
End With
End Sub