Solved

Run time Error 1004 on Excel Macro

Posted on 2014-11-19
2
206 Views
Last Modified: 2014-11-19
Hi, check my Macro on the "WTD Commentary", I am getting an Application -defined or obeject-defined error.Runtime Error 2004.
Its occuring on the line of code
        ActiveCell.FormulaR1C1 = _
        "=VLOOKUP(RC[-4],'[" & myfilename & "]" & MYSHEETNAME & "'!" & myrangename & ",16,FALSE)"

You need to have both Excel spreadsheets open at the same time when you run the Macro. Any ideas why?
WTD-Commentary-17112014.xlsm
DAILY-GSFI-PL-20141107.xlsx
0
Comment
Question by:Justincut
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 70

Expert Comment

by:Qlemo
ID: 40452764
You are populating FormulaR1C1, but using a standard addressing for the data table in myrangename. The result is
  =VLOOKUP(RC[-4],'[WTD-Commentary-17112014.xlsm]Hedges Exposure'!$D$7:$Z$50,16,FALSE)
but, as the commented example in your macro below that line shows, you need R1C1 addressing.
0
 
LVL 70

Accepted Solution

by:
Qlemo earned 500 total points
ID: 40452805
Using
myrangename = ActiveSheet.Range("D7:Z50").Address(ReferenceStyle := xlR1C1)

Open in new window

will do for this formula, but you have more of them in the macro, all requiring adjustment. Since they use static references, it should not be difficult to do so.
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Starting up a Project

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question