它已經有一段時間我用Excel中VBA數組所以請原諒我...使用動態數組VBA確定斜率和截距
我試圖定義基於是連續的匹配單元的動態數組循環確定。我確定我的語法是錯誤的,因爲我不知道如何定義數組。難點在於我的數組由一列中的大約6個連續行組成,再加上另一列中的另一個單元格組成。有任何想法嗎?
Sub calib_range()
Dim instrument As Variant
Dim calibrator As Variant
Dim lastrow As Integer
lastrow = ThisWorkbook.ActiveSheet.Range("b2").SpecialCells(xlCellTypeLastCell).Row
For i = 4 To lastrow
If Cells(i, 4) Like "MPC*" Then
'enter loop to determine length of MPC* array
For x = i + 1 To lastrow
If Cells(x, 4) = Cells(x - 1, 4) Then
Else
x = x - 1
Exit For
End If
Next x
instrument = Array(Cells(i, 17), Range(Cells(i, 14), Cells(x, 14)))
calibrator = Array(0, Range(Cells(i, 12), Cells(x, 12)))
Slope = Application.WorksheetFunction.Slope(instrument, calibrator)
Intercept = Application.WorksheetFunction.Intercept(instrument, calibrator)
Cells(i, 22) = Slope
Cells(i, 23) = Intercept
End If
Next i
End Sub
你有'細胞(X,4)=細胞(X - 1,4)Then',並直接轉到'Else' - 你丟失碼?爲什麼有'If'語句這樣寫? – BruceWayne
@BruceWayne它可能是兩個單元格中的值是相似的,因此它不會去其他地方。 – Vityata
@Vityata - 肯定 - 只是好奇,爲什麼不把它設置爲'If Cells()<> Cells Then // x = x-1 // Exit For'。 (對於凱爾的切向問題,我不認爲這是問題的一部分,只是我注意到的一部分。) – BruceWayne