我是VBA的新手,我正在尝试编写一个小脚本,它将根据输入框输出指定范围的单元格的斜率。理想情况下,我希望能够输入起始和结束单元格,并使其在这些范围内给出最佳拟合线的“斜率”。我真的很难让这个工作。非常感谢所有帮助。
Sub sloper()
Dim Start As Long
Dim Finish As Long
Dim v As Variant
Dim x As Variant
Dim y As Variant
Start = InputBox("What cell do the values start on?")
Finish = InputBox("What cell do the values end on?")
x = Range("E" & Start & ":E" & Finish) 'Deflection
y = Range("B" & Start & ":B" & Finish) 'Force
v = Application.LinEst(x, y, 1, 1) 'keeps returning the error
Range("L7") = v
End Sub
答案 0 :(得分:0)
也许改变你声明变量的方式,LINEST函数也需要有两个填充数值的范围,否则它将返回#VALUE
Sub sloper()
Dim Start As Long
Dim Finish As Long
Dim x As Range
Dim y As Range
Dim v As Variant
Start = InputBox("What cell do the values start on?")
Finish = InputBox("What cell do the values end on?")
Set x = Range("E" & Start & ":E" & Finish) 'Deflection
Set y = Range("B" & Start & ":B" & Finish) 'Force
v = Application.LinEst(x, y, 1, 1) 'keeps returning the error
Range("L7") = v
End Sub