Dim MaxRow As Integer
Dim MaxCol As Integer
Dim i, j, k, l As Integer
Dim Ma As Integer
Dim InnRise, InnFall As Integer
Dim QMC(1000) As Peak
Dim QMCNo As Integer
Dim Prange As Range
Dim chcol As IntegerPrivate Sub ComboBox2_Change()
chcol = ComboBox2.ListCount – 1
End Sub
Public Sub CommandButton2_Click()
k = 3
‘chcol = 2
Peakno = 0
Ma = 20
init = 500
level = 400
InnRise = 0
InnFall = 0
Init_ave = Application.WorksheetFunction.Average(Cells(2, chcol), Cells(init, chcol))
Init_stdev = Application.WorksheetFunction.StDev(Cells(2, chcol), Cells(init, chcol))
Init_Max = Application.WorksheetFunction.Max(Cells(2, chcol), Cells(MaxRow, chcol))
Init_lMin = Application.WorksheetFunction.Min(Cells(2, chcol), Cells(MaxRow, chcol))
Cells(1, MaxCol + 1) = “MA5”
Cells(1, MaxCol + 2) = “startK”
Cells(1, MaxCol + 3) = “endK”
Cells(1, MaxCol + 4) = “PeakNo”
Cells(1, MaxCol + 5) = “PeakValue”
Cells(1, MaxCol + 6) = “DataNo”
Cells(1, MaxCol + 7) = “ZeroCross”
‘==============================Langle MA 5========================================================
For i = 2 To MaxRow
Cells(i, MaxCol + 1) = Application.WorksheetFunction.Average(Cells(i, chcol), Cells(i + 5, chcol))
Next i
‘=================================================================================================
‘—————–L MA5 ZeroCross Range_Fall———————————————
For i = 2 To MaxRow
Cells(i, MaxCol + 6) = i – 1
P0 = Cells(i, MaxCol + 1)
P1 = Cells(i + 1, MaxCol + 1)
P2 = Cells(i + 2, MaxCol + 1)
P3 = Cells(i + 3, MaxCol + 1)
If P0 > 0 And P1 < 0 And P2 < 0 And P3 < 0 And InnFall = 0 Then
InnFall = 1
startK = i
Cells(k, MaxCol + 2) = i
End If
If P0 < 0 And P1 > 0 And P2 > 0 And P3 > 0 And InnFall = 1 Then
endK = i
Cells(k, MaxCol + 3) = i
k = k + 1
InnFall = 0
End If
Next i
‘——————-Peak Fall —————————–
MaxK = Cells(3, MaxCol + 2).End(xlDown).Row
‘===========================Peak Fall==============================
For i = 3 To MaxK
startK = Cells(i, MaxCol + 2)
endK = Cells(i, MaxCol + 3)
Set Prange = Range(Cells(startK, chcol), Cells(endK, chcol))
Peak_Min = Application.WorksheetFunction.Min(Prange)
Cells(i, MaxCol + 4) = WorksheetFunction.Match(Peak_Min, Prange, 0) + startK
Cells(i, MaxCol + 5) = Peak_Min
‘If k > 2 Then
‘ Cells(k, chcol + 5) = Cells(k, chcol + 3) – Cells(k – 1, chcol + 3)
‘ End If
‘=============================================================
Next i
‘===========================Zero Cross==============================
zeroed = 0
For k = 3 To MaxK
startK = Cells(k, MaxCol + 2)
endK = Cells(k + 1, MaxCol + 2)
‘Set Prange = Range(Cells(startK, chcol), Cells(endK, chcol))
‘Peak_Min = Application.WorksheetFunction.Min(Prange)
For j = startK + 10 To endK – 10
If Cells(j, chcol) < 0 And Cells(j + 1, chcol) > 0 And zeroed = 0 Then
zeroK = j
Cells(k, MaxCol + 7) = zeroK
zeroed = 1
End If
Next j
zeroed = 0
‘If k > 2 Then
‘ Cells(k, chcol + 5) = Cells(k, chcol + 3) – Cells(k – 1, chcol + 3)
‘ End If
‘=============================================================
Next k
End Sub
Private Sub UserForm_Click()
End Sub
Private Sub CommandButton1_Click() ‘OPEN CSV FILE
OpenFileName = Application.GetOpenFilename(“CPLTファイル,*.csv?”)
Workbooks.Open OpenFileName
TextBox1.Value = OpenFileName
ActiveSheet.Name = “sheet1”
MaxRow = Range(“A2”).End(xlDown).Row
MaxCol = Range(“A2”).End(xlToRight).Column
ch = MaxCol
dataN = MaxRow
For i = 0 To MaxCol – 1
ComboBox2.AddItem Str(i + 1)
Next i
ComboBox2.ListIndex = 1
Worksheets.Add.Name = “sheet2”
Worksheets(“Sheet1”).Activate
End Sub |