我已經嘗試了一切,包括在論壇上閱讀關於錯誤1004應用程序定義或對象定義的錯誤,但我找不到任何東西,正在幫助我修復錯誤。它在立即窗口中寫入正確的公式。這裏是代碼。我已經把代碼中的錯誤放在了哪裏。Error 1004 vba excel當進入到單元格中的查找公式
變量的定義主要有以下幾種,我已經在錯誤1004
Dim templateName As String ' = "Company 1" and yes this worksheet exists in my file
Dim servicesRow As Integer ' = 22
Dim j as Integer ' = 1
Public firstProjectSOF as Range ' firstProjectSOF.Row = 5
Dim columnTemp As Variant ' columnTemp(0) = "A"
Public lastProjectSOF as Range ' lastProjectSOF.Row = 65
Dim Rng as Range ' Rng.Column = 17
For j = 1 To numEmployees
With Sheets("SOF").Range("E5", Range("E5").End(xlToRight)) 'Finds the cell in SOF of that employee's last name
Set Rng = .Find(What:=employees_lastName(j), _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False)
End With
'This is where the error 1004 occurs, on trying to write the VLOOKUP formula into the cell
Sheets(templateName).Range(Cells(servicesRow + 1 + j, 5)).FormulaLocal = "=VLOOKUP($G$10,'Staff Output Final'!B" & firstProjectSOF.Row & ":" _
& columnTemp(0) & lastProjectSOF.Row & "," & (Rng.Column - 1) & ",FALSE)"
Next
對於信息的時間包含在監視窗口中的值,如果是相關的,我的電腦是從Mac加拿大(英文),但我最近在法國的一臺PC電腦上編輯了這個文件(使用法文版的操作系統)。爲了防止出現問題,我只是嘗試在我的Mac上創建一個新的excel文件,並將舊文件中的選項卡複製並粘貼到新文件中,但仍然收到Error 1004 ...
謝謝你的幫助!非常感激!
你在哪裏初始化'lastProjectSOF'? –
對不起,「初始化」是什麼意思?你的意思是「我賦值的地方」?我使用一個輸入框,Set lastProjectSOF = Application.InputBox(Prompt:=「在Staff Output Final中,選擇列B中具有項目編號的最後一個單元格」,標題:=「STAFF OUTPUT FINAL,Last Cell in Range」, Type:= 8) – sox373
我剛剛添加了'lastProjectSOF'是一個Public變量的信息。 – sox373