我有这个代码插入某个值及其后续列,但我在向另一个工作表报告时遇到问题。我目前在将派生结果报告给另一张表时遇到问题
Sub interp()
Dim temp As Long
Dim var As Long
Dim var1 As Long
Dim xs As Range
Dim ys As Range
Dim lastrow As Long
Dim lastcol As Long
Dim vy As Long
temp = Sheet2.Range("a1").Value
With Worksheets(1)
lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
lastcol = ActiveSheet.Cells(2, Columns.Count).End(xlToLeft).Column
Set xs = Range(Cells(2, 1), Cells(lastrow, 1)) 'range for xs values
For vy = 2 To lastcol 'interpolating from second column to last
Set ys = Range(Cells(2, vy), Cells(lastrow, vy))'selecting the column based on value of vy
var = WorksheetFunction.Match(temp, xs, 1)'for forecasting estimated values
var1 = var + 1 'for forecasting estimated values
y = .Range(ys.Cells(var, 1), ys.Cells(var1, 1)).Value 'for forecasting estimated values
x = .Range(xs.Cells(var, 1), xs.Cells(var1, 1)).Value 'for forecasting estimated values
Sheet2.Range(Cells(1, vy)).Value = Application.WorksheetFunction.Forecast(temp, y, x) 'interpolated value is put in a cell dependent the value of vy
Next vy
End With
End Sub