?
Solved

Copying data using key column and excluding #N/A

Posted on 2013-01-24
2
Medium Priority
?
231 Views
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.ClearContents
    Selection.FormulaR1C1 = _
        "=VLOOKUP(RC[-7],[Book2.xls]Sheet1!R5C3:R181C4,2,FALSE)"
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?
0
Comment
Question by:Mamarazzi
[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 Comments
 
LVL 93

Accepted Solution

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



Sub Copy_Formula()
    With Selection
        .ClearContents 
        .FormulaR1C1 = _
            "=IF(ISNA(VLOOKUP(RC[-7],[Book2.xls]Sheet1!R5C3:R181C4,2,FALSE)),"""",VLOOKUP(RC[-7],[Book2.xls]Sheet1!R5C3:R181C4,2,FALSE))" 
        .Value = .Value
    End With
End Sub

Open in new window


In Excel 2007 and later:

Sub Copy_Formula()
    With Selection
        .ClearContents 
        .FormulaR1C1 = _
            "=IFERROR(VLOOKUP(RC[-7],[Book2.xls]Sheet1!R5C3:R181C4,2,FALSE),"""")" 
        .Value = .Value
    End With
End Sub

Open in new window

0
 

Author Closing Comment

by:Mamarazzi
ID: 38814112
Fabolous! Thanks
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

777 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