Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

excel vba how to add formula

Posted on 2016-07-21
5
Medium Priority
?
56 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
[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
5 Comments
 
LVL 34

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

660 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