我在尝试使用此vlookup时收到此错误1004。我使用窗口选择文件,然后在vlookup中使用该文件。我在另一个宏中做到这一点,我使用了基本相同的代码。但由于某种原因,这个不起作用。任何人都可以看到任何明显的问题吗?我无法弄清楚我做错了什么。
我在"使用ws"
后立即获得第一个VLOOKUP公式的错误Dim iRet As Integer
Dim strPrompt As String
Dim strTitle As String
Dim shtName As String
' Prompt
strPrompt = "Please select the last Kronos Full File before the dates of this Report." & vbCrLf & _
"For example, if the date of this report is 9-8-17, you would want to use the closest date Kronos Full File." & vbCrLf & _
"If one was not ran in the past couple days, then run a new Kronos Full File, and then choose that file."
' Dialog's Title
strTitle = "Latest Kronos Full File"
'Display MessageBox
iRet = MsgBox(strPrompt, vbOK, strTitle)
Dim Window2 As String
Dim X As String
Dim lNewBracketLocation As Long
Dim wb2 As Workbook
Window2 = Application.GetOpenFilename( _
FileFilter:="Excel Files (*.xls*),*.xls*", _
Title:="Choose the Newest Kronos Full File", MultiSelect:=False)
Set wb2 = Workbooks.Open(Filename:=Window2, ReadOnly:=True)
shtName = wb2.Worksheets(1).name
wb2.Close
MsgBox "You selected " & Window2
'Find the last instance in the string of the path separator "\"
lNewBracketLocation = InStrRev(Window2, Application.PathSeparator)
'Edit the string to suit the VLOOKUP formula - insert "["
X = Left$(Window2, lNewBracketLocation) & "[" & Right$(Window2, Len(Window2) - lNewBracketLocation)
With ws
.Range("M2").Formula = "=VLOOKUP($K2,'" & X & "]shtName'!$B$2:$E$99999,4,0)"
.Range("N2").Formula = "=VLOOKUP($K2,'" & X & "]shtName'!$B$2:$C$99999,2,0)"
.Range("O2").Formula = "=VLOOKUP($K2,'" & X & "]shtName'!$B$2:$U$99999,20,0)"
.Range("P2").Formula = "=VLOOKUP($K2,'" & X & "]shtName'!$B$2:$Q$99999,16,0)"
.Range("Q2").Formula = "=VLOOKUP($K2,'" & X & "]shtName'!$B$2:$S$99999,18,0)"
End With
答案 0 :(得分:1)
使用其他工作簿中的>>> result = gmodel.fit(y_test, x=x_test)
>>> print(result.fit_report())
[[Model]]
Model(fu)
[[Fit Statistics]]
# function evals = 11
# data points = 8
# variables = 3
chi-square = 2.159
reduced chi-square = 0.432
Akaike info crit = -4.479
Bayesian info crit = -4.241
[[Variables]]
a: 0.12619047 +/- 0.050695 (40.17%) (init= 0.4285)
c: -0.55833335 +/- 0.553020 (99.05%) (init= 0.057)
b: -0.52857141 +/- 0.369067 (69.82%) (init=-1.71)
[[Correlations]] (unreported correlations are < 0.100)
C(a, b) = -0.962
C(c, b) = -0.793
C(a, c) = 0.642
地址的另一种方法是设置范围,稍后您可以使用import matplotlib.pyplot as plt
from lmfit import Model
import numpy as np
def fu(x,a=0.4285,b=-1.71,c=0.057):
return x*x*a + x * b + c
gmodel = Model(fu)
print "Params" , gmodel.param_names
print "Independent var", gmodel.independent_vars
params = gmodel.make_params()
print " Params prop", params
data_test = np.array([[0,0], [1,-1.2], [2, -2], [3,-1.3], [4,0], [5,0.5], [6,0.9], [7, 1.5]])
x_test = data_test[:,0]
y_test = data_test[:,1]
result = gmodel.fit(y_test, x=x_test)
print(result.fit_report())
plt.plot(x_test, y_test, 'bo')
plt.plot(x_test, result.init_fit, 'k--')
plt.plot(x_test, result.best_fit, 'r-')
plt.show()
。如果需要,第4个参与者将添加工作表和工作簿的名称。
Range
答案 1 :(得分:0)
似乎我的问题与我尝试使用VLOOKUP的范围有关。看起来,一旦我将99999更改为仅9999,那么它看起来就像VLOOKUP一样。我仍然不确定为什么,但我很确定是这样的。当我降低该数字范围时,我没有收到任何错误消息。我猜是因为它超出了实际工作表的范围或其他东西。