+ Reply to Thread
Results 1 to 6 of 6

Search and If found return adjacent cell [Solved]

  1. #1
    Registered User
    Join Date
    01-15-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    18

    Search and If found return adjacent cell [Solved]

    Hello all,

    I am working on a macro to compare two separate workbooks for accuracy on our reporting. I previously was using a line formula as shown here after merging them onto the same workbook but separate sheets:

    =IFERROR(INDEX('Data1'!$D:$D,MATCH($A178,'Data1'!$C:$C,0)),"")
    =IFERROR(INDEX('Data2'!$D:$D,MATCH($A178,'Data2'!$N:$N,0)),"")

    I then just drag the formula down to search each line item against the secondary database. It has been working this way but I started messing with the VBA and think I can get a much cleaner/simpler result. Also one that can be easily transferred to other employees as an add-on

    Simply put, I have a two columns (A, B). Column A holds a special code associated with a box letter sequence in column B.
    I uploaded a spreadsheet with this to help you understand.

    How can I:

    search using the contents of cell A2 against Sheet2 column A
    if found then copy adjacent cell (column B) on Sheet2 to Sheet1 column C?
    if not found then write "not found"
    repeat using contents of cell A3, then A4, etc until end.

    I really don't have the experience or knowledge to even get started on this and my Goggle searches have yielded nothing positive.
    Attached Files Attached Files
    Last edited by jpullen88; 03-30-2016 at 08:43 AM.

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Search and If found return adjacent cell

    Hello,

    formulas will always be more efficient than rolling your own with VBA. If you want to optimise performance, stick with the formulas.

    cheers, teylyn

  3. #3
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Search and If found return adjacent cell

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    01-15-2015
    Location
    USA
    MS-Off Ver
    2013
    Posts
    18

    Re: Search and If found return adjacent cell

    Teylyn,
    Forgive my ignorance but why is this?

    Rcm,
    That worked beautifully! Thank you very much!

  5. #5
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: Search and If found return adjacent cell

    you are welcome just marke it as solved

  6. #6
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Search and If found return adjacent cell

    Quote Originally Posted by jpullen88 View Post
    Forgive my ignorance but why is this?
    Because formulas use the super efficient internal calculation engine of Excel, where as VBA adds another processing layer on top. Also, in this example VBA is used to loop through all cells and uses a read and/or write operation for each cell. That is very inefficient and there are ways to write faster VBA. In addition, formulas will update when the precendent cells change, whereas the VBA routine will have to be repeated. This can be automated, of course, but effectively you're re-inventing the wheel and replacing Excel's built-in Tesla with a tricycle.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Search for value in row and return adjacent cell
    By lindseyd32833 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-11-2020, 04:03 PM
  2. Search for value, return value in adjacent cell
    By laerm in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 2
    Last Post: 08-13-2013, 01:12 PM
  3. Search for specific value in a row, then return content og adjacent cell
    By linaudio in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-20-2013, 09:11 AM
  4. [SOLVED] Search for a string within a cell, if found, return value of 1
    By brookenovak in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-07-2013, 07:39 PM
  5. [SOLVED] Formula needed to return the text adjacent to the cell when found.
    By LMWI65 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-16-2012, 08:18 AM
  6. SEARCH MACRO FOR VALUE IN WORKBOOK, RETURN value of adjacent cell.
    By thequiff in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 06-15-2012, 10:47 AM
  7. Replies: 4
    Last Post: 05-07-2012, 10:53 PM
  8. Replies: 4
    Last Post: 05-12-2011, 02:25 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1