Run-time error 1004 when trying to insert VLOOKUP in cell

hagea_dan

New Member
Joined
Aug 14, 2014
Messages
19
Hi,

I'm trying to insert in a range a VLOOKUP formula that will return data from another closed workbook but the line where the formula is inserted returns error 1004

Here is the code:

Code:
Sub insFormula()
Dim c As Range
Dim LastRow As Integer


With ActiveSheet
    LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    For Each c In .Range("A2:A" & LastRow)
        c.Offset(0, 4) = "=VLOOKUP(" & c.Address(0, 0) & ";'C:\Users\Dan\Desktop\[stoc.xlsx]stoc total'!B:I;8;0)"
    Next c


End With


End Sub

If I manually enter the formula and replace the dynamic cell address part it works.
Can someone please tell me what is the problem with this code?
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Are you sure that your separators are ; as it works fine for me if I change them to commas, I get...

=VLOOKUP(A2,'C:\Users\Dan\Desktop\[stoc.xlsx]stoc total'!B:I,8,0)
 
Upvote 0
Are you sure that your separators are ; as it works fine for me if I change them to commas, I get...

My separator when entering a formula manually is semi-colon. I guess it has something to do with my region.
I've replaced them in the code with commas as you said and it works but if I check the formula in the formula bar the separator is still semi-colon. Very strange.
Thank your for your help.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top