+ Reply to Thread
Results 1 to 2 of 2

vba to search cell values in another workbook's column

  1. #1
    Registered User
    Join Date
    06-10-2014
    Posts
    15

    vba to search cell values in another workbook's column

    Hi All,
    I have a column "F" in workbook1 containing some values (obtained after using some excel formulas to extract and concatenate from other columns) like
    blah-rd1
    blah-rd5
    blah-rd6
    blah-rd48do I want to do this
    blah-rd100
    etc

    I have another column "D" in workbook2 containing values like
    rndm-blah-rd1_sgjgs
    hjdf-blah-rd5_cnnv
    sdfhjdf-blah-rd100_cfdnnv
    ect

    Basically "Blah-rdxx" is always present alongwith other strings in D column of workbook2

    Now, what I want to do is -
    If value in D column of workbook2 contains value of F column of workbook1 Then
    copy corresponding value of S column of workbook2 in H column of workbook1 (5th column)


    This is where I have reached so far but it doesnt copy anything probably coz there is some problem in Cells(w.Row, 2).Copy (w1.Cells(K, 5)) -

    Please Login or Register  to view this content.
    Thanks for your help in advance.
    Last edited by shopaholic; 04-17-2018 at 04:55 PM.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: vba to search cell values in another workbook's column

    You're correct, Cells(w.Row, 2).Copy doesn't have a qualified worksheet. So it defaults to the currently active sheet which I'm guessing is Book1-Sheet1.

    Try this...
    w2.Cells(w.Row, 2).Copy w1.Cells(K, 5)

    A couple of other comments:

    1.) blah-rd1 will partial match with blah-rd100. A way around that is if the values in Book2 always have a trailing underscore e.g.; blah-rd100_, then if you search for blah-rd1_, it can't match blah-rd100_
    v = r.Value & "_"

    2.) If you only have one match, then after you copy\paste, use Exit For to stop searching for that rd value.

    3.) The .Find method is a faster search.
    Last edited by AlphaFrog; 04-17-2018 at 09:54 PM.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

+ 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. Replies: 5
    Last Post: 01-30-2018, 07:32 AM
  2. Two Workbooks - Search for Values in Workbook 2, Copy and Paste in Workbook 1
    By CC268 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-27-2017, 11:17 AM
  3. VBA search if values from one range in another workbook and copy different column **urgent
    By Greg_Tilearcio in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-08-2015, 01:12 PM
  4. Search cell values from range in another workbook and copy found row to a 3rd workbook.
    By SierraKilo78 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-09-2014, 01:09 PM
  5. Search textbox value in a different workbook and display other column values in userform
    By SierraKilo78 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-24-2014, 01:29 PM
  6. Open Workbook and Search based on column values
    By kboy1289 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-18-2013, 01:41 PM
  7. Search multiple workbook headers and copy column entries to another workbook
    By R3n3gad3-XtC in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-13-2012, 12:47 AM

Tags for this Thread

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