Error 1004 vba excel when entering vlookup formula into cell

sox373

I have tried everything, including reading many questions in the forum about Error 1004 Application Defined or Object-Defined Error, but I can't find anything that is helping me fix the error. It writes the correct formula in the Immediate window.Here is the code. I've put where I get the error in the code.

The variable definitions are the following, and I've included the values in the watch window at the time of the Error 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

For info, if it is relevant, my computer is a Mac from Canada (English), but I recently edited the file on a PC computer in France (with OS in French). Just in case that was creating problems, I just tried creating a new excel file on my Mac in and copying and pasting the tabs from the old file into the new one, but I am still getting the Error 1004...

Thanks for any help! Much appreciated!

sox373

In fact, I just tried something by chance and it worked.... I removed Range, and just left the Cells part, so the code became:

Sheets(templateName).Cells(servicesRow + 1 + j, 5).FormulaLocal = "=VLOOKUP($G$10,'Staff Output Final'!B" & firstProjectSOF.Row & ":" _
& columnTemp(0) & lastProjectSOF.Row & "," & (Rng.Column - 1) & ",FALSE)"

I'm not quite sure why this works, but it does....

Does anyone know why??? Since higher up in the same code, I use the following code to assign a VLOOKUP formula to another cell, and it worked with "Range" no problems.

Sheets(templateName).Range("A18:H18").FormulaLocal = "=VLOOKUP($G$10,'PEIINV2 - paste here'!B" & firstProjectPEIINV.Row & ":AH" & lastProjectPEIINV.Row & _
",2,FALSE)"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Excel VBA Run-time error 1004 when inserting or value formula into cell

From Dev

VBA vlookup iferror formula error '1004'

From Dev

Excel - VBA - formula error 1004 -

From Dev

Excel VBA Vlookup Runtime Error 1004

From Dev

Excel 2010 VBA Error 1004 with formula

From Dev

Excel VBA: Error 1004 WorkSheetFunction 'Unable to get Vlookup property"

From Dev

Vlookup + Iferror in VBA error "1004"

From Dev

Excel VBA Formula - 1004 object or application defined error

From Dev

Excel Vlookup Formula in VBA with Variables

From Dev

Error 1004: Excel VBA

From Dev

Error 1004: Excel VBA

From Dev

VBA VLOOKUP Formula Compile error

From Dev

VBA error '1004' when accessing cell values within 2 loops

From Dev

VBA using vlookup of indirect range for formula in cell

From Dev

Return the downside cell in an Excel Vlookup formula

From Dev

Entering excel formula with quotations in a loop using VBA

From Dev

Excel VBA: Formula Not Entering Correctly From String

From Dev

Error when entering Excel

From Dev

Excel IF cell reference formula being changed when recorded in VBA

From Dev

Runtime error 1004 with Count and Countif formula VBA

From Dev

Runtime error 1004 with Count and Countif formula VBA

From Dev

Error 1004 - Vlookup in vba - Unable to get the Vlookup property of the WorksheetFunction class

From Dev

Excel VBA Runtime Error 1004 when renaming ActiveSheet

From Dev

Runtime error 1004 when deleting multiple columns in excel VBA

From Dev

Excel VBA Runtime 1004 error on Autofill when running on another PC

From Dev

Excel VBA runtime error 1004

From Dev

Excel VBA runtime error '1004'

From Dev

Excel VBA runtime error 1004

From Dev

excel vba error 1004 Range

Related Related

HotTag

Archive