Solved

excel vba how to add formula

Posted on 2016-07-21
5
45 Views
Last Modified: 2016-07-27
I'm getting error when I assign below formula to field A21

Run time error 1004
Application defined or object defined error
 
    Range("A21").Select
    ActiveCell.FormulaR1C1 = "=VLOOKUP(A2,Sheet2!$A$10:$R$90,3,FALSE)"
    Range("A21").Select

If I apply same formula manually on cell A21 by pressing F2 the commend works.
0
Comment
Question by:Bharat Guru
  • 2
  • 2
5 Comments
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
ID: 41723802
Your formula uses A1 notation, not R1C1, try this.
    Range("A21").Formula = "=VLOOKUP(A2,Sheet2!$A$10:$R$90,3,FALSE)"

Open in new window

0
 
LVL 3

Expert Comment

by:AL_XResearch
ID: 41723804
Yes of course. You are assigning an A1 style formula to the R1C1 formula property.

If you want to assign that formula you should just use the 'mycell.formula' property
0
 
LVL 3

Expert Comment

by:AL_XResearch
ID: 41723807
Looks like a split-second clash of experts :)
0
 

Author Comment

by:Bharat Guru
ID: 41730167
Thanks
0
 

Author Closing Comment

by:Bharat Guru
ID: 41731660
Thanks
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now