Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

excel vba how to add formula

Posted on 2016-07-21
5
Medium Priority
?
59 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 35

Accepted Solution

by:
Norie earned 2000 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

916 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