Copying data using key column and excluding #N/A

Posted on 2013-01-24
Last Modified: 2013-01-24
I want to copy data from one workbook to another using a key column that exist in both.

So far I've tried using VLOOKUP but I'm not sure it is the best way.

I have a button that runs a macro. First I select the cells I want the formula in:

Sub Copy_Formula()
    Selection.FormulaR1C1 = _
End Sub

This works fine, BUT... I want the values in the cells, not the formula itself. And I want to clear the #N/A that I get in the cells if the formula has no match.

Any idea?
Question by:Mamarazzi
LVL 92

Accepted Solution

Patrick Matthews earned 500 total points
ID: 38813988
Using Excel 2003...

Sub Copy_Formula()
    With Selection
        .FormulaR1C1 = _
        .Value = .Value
    End With
End Sub

Open in new window

In Excel 2007 and later:

Sub Copy_Formula()
    With Selection
        .FormulaR1C1 = _
        .Value = .Value
    End With
End Sub

Open in new window


Author Closing Comment

ID: 38814112
Fabolous! Thanks

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Find Minimum and Maximum Dates in a column using Power Query 15 48
location range 4 22
Problem to With line 4 39
Fixing a embedded format 7 29
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 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…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

914 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

18 Experts available now in Live!

Get 1:1 Help Now