Solved

excel vba how to add formula

Posted on 2016-07-21
5
49 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

815 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

8 Experts available now in Live!

Get 1:1 Help Now