In VBA, a 'Find' routine that looks for multiple possibilities

Posted on 2011-10-11
Last Modified: 2012-05-12
How do I rewrite this line of code so that it will look for #N/A errors as well? In this particular situation it can be either one.

Set top = Columns("B").Find("#REF!", , xlValues, xlWhole)

Open in new window

Question by:gabrielPennyback
    LVL 48

    Expert Comment

    You can only look that for one value. Do that twice for the two possibilities
    LVL 23

    Accepted Solution

    You could incorporate ISERROR into your page formula and that way you could ensure that you only need to search for one item or even avoid doing the find at all

    LVL 3

    Assisted Solution

    What are the actions you take in your code after you find the #REF or #N/A?
    Will different actions need to be taken, depending on #REF or #N/A?
    If so, follow ipaulino's answer. If not go with Michael's answer.
    The formula in column B on your worksheet would be something like:

    = IF(ISERROR(your current formula),"ERROR",your current formula)
    Adjust your code to:
    Set top = Columns("B").Find("ERROR!", , xlValues, xlWhole)

    LVL 1

    Author Closing Comment

    I managed to put something together with elements of both your solutions. Thanks!

    - John

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Suggested Solutions

    I've recently been in need of an Excel macro that could add a letter before the text on multiple cells in an Excel document. My English is as it is, so I will try explain what it does diffrently. If you have an excel document with 2000 rows an…
    Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
    Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
    This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

    728 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

    25 Experts available now in Live!

    Get 1:1 Help Now