Sub GraphData()
Dim GraphStart As Integer
Dim GraphEnd As Integer
Dim TimeRange As Range
Dim AssayRange As Range
Dim LastRow As Integer
Dim AssayTime As Date
Dim k As Integer
Dim m As Integer
LastRow = ActiveWorkbook.Worksheets("RawData").Range("B15").Value + 17
For k = 18 To LastRow
If ActiveWorkbook.Worksheets("RawData").Range("H" & k).Value < 2 Then
GraphStart = k + 1
End If
Next
For m = 18 To LastRow
If ActiveWorkbook.Worksheets("RawData").Range("H" & m).Value < 32 Then
GraphEnd = m
End If
Next
Set TimeRange = Application.Range(Cells(GraphStart, "F"), Cells(GraphEnd, "F"))
Set AssayRange = Application.Range(Cells(GraphStart, "H"), Cells(GraphEnd, "H"))
ActiveWorkbook.Worksheets("Assay Result").Range("D31").Value = Application.WorksheetFunction.Slope(AssayRange, TimeRange)
ActiveWorkbook.Worksheets("Assay Result").Range("D32").Value = (Application.WorksheetFunction.Correl(AssayRange, TimeRange)) ^ 2
ActiveWorkbook.Worksheets("Assay Result").Range("D33").Value = Round(Application.WorksheetFunction.Min(AssayRange), 2) & " to " & Round(Application.WorksheetFunction.Max(AssayRange), 2)
End Sub
我相信以前有人有这个问题。错误是不一致的,有时会发生。
答案 0 :(得分:0)
试试这个。
Sub GraphData()
Dim GraphStart As Integer
Dim GraphEnd As Integer
Dim TimeRange As Range
Dim AssayRange As Range
Dim LastRow As Integer
Dim AssayTime As Date
Dim k As Integer
Dim m As Integer
Dim Ws As Worksheet, toWs As Worksheet
Dim Wf As WorksheetFunction
Set Wf = WorksheetFunction
Set Ws = Worksheets("RawData")
Set toWs = Worksheets("Assay Result")
With Ws
LastRow = .Range("B15").Value + 17
For k = 18 To LastRow
If .Range("H" & k).Value < 2 Then
GraphStart = k + 1
End If
Next
For m = 18 To LastRow
If .Range("H" & m).Value < 32 Then
GraphEnd = m
End If
Next
Set TimeRange = .Range("F" & GraphStart, "F" & GraphEnd)
Set AssayRange = TimeRange.Offset(, 2)
End With
With toWs
.Range("d31") = Wf.Slope(AssayRange, TimeRange)
.Range("d32") = Wf.Correl(AssayRange, TimeRange) ^ 2
.Range("d33") = Round(Wf.Min(AssayRange), 2) & " to " & Round(Wf.Max(AssayRange), 2)
End With
End Sub