+ Reply to Thread
Results 1 to 17 of 17

Finding text in column B, then copying corresponding value from column A into new sheet

Hybrid View

antibudger Finding text in column B,... 02-13-2014, 03:25 PM
Bernie Deitrick Re: Finding text in column B,... 02-13-2014, 04:02 PM
Arkadi Re: Finding text in column B,... 02-13-2014, 04:06 PM
Bernie Deitrick Re: Finding text in column B,... 02-13-2014, 04:18 PM
antibudger Re: Finding text in column B,... 02-13-2014, 05:00 PM
Bernie Deitrick Re: Finding text in column B,... 02-13-2014, 05:18 PM
antibudger Re: Finding text in column B,... 02-13-2014, 05:44 PM
antibudger Re: Finding text in column B,... 02-13-2014, 05:34 PM
Bernie Deitrick Re: Finding text in column B,... 02-13-2014, 05:55 PM
antibudger Re: Finding text in column B,... 02-13-2014, 07:05 PM
Bernie Deitrick Re: Finding text in column B,... 02-14-2014, 10:06 AM
antibudger Re: Finding text in column B,... 02-14-2014, 01:40 PM
Bernie Deitrick Re: Finding text in column B,... 02-15-2014, 05:41 PM
antibudger Re: Finding text in column B,... 02-17-2014, 05:33 PM
Bernie Deitrick Re: Finding text in column B,... 02-17-2014, 11:28 PM
antibudger Re: Finding text in column B,... 02-20-2014, 07:52 PM
Bernie Deitrick Re: Finding text in column B,... 02-21-2014, 10:45 AM
  1. #1
    Registered User
    Join Date
    02-13-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Finding text in column B, then copying corresponding value from column A into new sheet

    Hello!

    I would greatly appreciate guidance in trying to solve a problem that I anticipate will be occurring frequently in my huge data sheet.

    I have multiple sheets in my workbook. In sheet 2, I would like to identify a text name in column B, and if found I would like to copy the value from its corresponding row in column A to sheet 1 column B when the text is identified in sheet 1 column A. In sheet 1, the text will only appear once. In sheet 2, the text will likely occur many times.

    I will try to clarify by providing the example:

    In sheet 1, I have "diseases" listed alphabetically in column A. In sheet 2, I have breeds of dogs listed alphabetically in column A and diseases that they are predisposed to listed in column B. I would like identify all breeds in sheet 2 that have a disease, and list all those breeds in sheet 1 under column B of the corresponding disease. I hope that makes more sense.

    I hope this makes sense and is feasible to program? I thank you in advance for any help!


    Andrea
    Last edited by antibudger; 02-13-2014 at 04:04 PM.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,302

    Re: Finding text in column B, then copying corresponding value from column A into new shee

    Quote Originally Posted by antibudger View Post
    I have multiple sheets in my workbook. In sheet 2, I would like to identify a text name in column B, and if found I would like to copy the value from its corresponding row in column A to sheet 1 column B when the text is identified in sheet 1 column A. In sheet 1, the text will only appear once. In sheet 2, the text will likely occur many times.
    Andrea,

    If by identify you mean select:

    Sub test()
    Dim lngR As Long
    lngR = Application.Match(ActiveCell.Value, Sheets("Sheet1").Range("A:A"), False)
    Sheets("Sheet1").Range("B:B").Cells(lngR).Value = ActiveCell.Offset(0, -1).Value
    End Sub
    If by identify you mean something else, post back.

    Or you could just use a formula in column B of Sheet1 that will pull the last (lowest down the sheet) entry from Sheet2, base on the value in A2 - this needs to be array-entered (enter using Ctrl-Shift-Enter) and skip the macro altogether.

    Formula: copy to clipboard
    =INDEX(Sheet2!$A$1:$A$1000,MAX(IF(Sheet2!$B$1:$B$1000=Sheet1!A2,ROW($A$1:$A$1000))))

  3. #3
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Finding text in column B, then copying corresponding value from column A into new shee

    If I understand correctly, you want to search for a value in sheet2, column B, and write the same line column A value to sheet1. I have based the code on sheet names, not ordinal position, and at the moment it would prompt for the search value. It also checks sheet1 to write to the next available blank line.

    This may work for you:

    Sub vlook()
    Dim i, last_read_row, writerow As Integer
    Dim target As String
    target = InputBox("Please enter the text you wish to find") 'to get the search value
    last_read_row = Worksheets("Sheet2").Range("B" & Rows.Count).End(xlUp).Row ' last row with data on sheet2
    writerow = Worksheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row + 1 'finds last row with data on sheet1 and will start writing at next cell.  Only bad thing, it will not use A1 but start at A2
    
    For i = 1 To last_read_row
        If CStr(Worksheets("Sheet2").Cells(i, 2).Value) = target Then
            Worksheets("Sheet1").Cells(writerow, 1).Value = Worksheets("Sheet2").Cells(i, 1).Value 'copy value to sheet2 if match found
            GoTo found 'stop checking after value found
        End If
    Next i
    MsgBox ("Sorry could not find the search value.")
    found:
    End Sub

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,302

    Re: Finding text in column B, then copying corresponding value from column A into new shee

    That is different, and should not use a macro:

    Select the table of Breed vs Disease, and from the insert menu, choose Pivot table.

    Select Breed and Disease as row labels and you will get a nice headed list of Breed followed by a list of their diseases, and if you move Disease above Breed, a headed list of Diseases followed by the breeds affected, like so:

    PT.jpg

  5. #5
    Registered User
    Join Date
    02-13-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Finding text in column B, then copying corresponding value from column A into new shee

    example.xlsx

    Hi Bernie & Arkadi -

    I don't think the Pivot Table will work because I have a lot of columns in sheet 1, in addition to disease. I have symptoms, medications, etc... and want to list breed predispositions in one of the columns. I also am trying to list all breeds (which may range from 0 to 210) predisposed to said disease into 1 cell on sheet 1, which would correspond to that disease. So the disease is the primary identifier in sheet 1, but the breed is the primary identifier in sheet 2, and I am trying to list all the breeds in sheet in a separate column. I have made a small example - hopefully it uploads correctly.

  6. #6
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,302

    Re: Finding text in column B, then copying corresponding value from column A into new shee

    It uploaded correctly, but does not have all the information that you described and that would be need for a solution. Why not post the entire workbook?

    And what cell do you want the list in? in a new blank column next to the disease name? Would you want a drop down on the cell, or have all the breeds for that disease shown as a list in the cell? Or a comment that would pop up when you select the cell with the disease name?

  7. #7
    Registered User
    Join Date
    02-13-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Finding text in column B, then copying corresponding value from column A into new shee

    Dear Arkadi,

    I am not able to get your macro to work, it keeps sending the 'not found' error. Am I correct in thinking that if a concantenate function were placed during the search, it would place all breeds into one cell?

    Thank you for your help!

  8. #8
    Registered User
    Join Date
    02-13-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Finding text in column B, then copying corresponding value from column A into new shee

    Oh, you don't want the entire workbook - way too much raw data, and it is a legal document so I can't "legally" share it. Did you see both sheet 1 and sheet 2 in the example?

  9. #9
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,302

    Re: Finding text in column B, then copying corresponding value from column A into new shee

    I only saw Sheet1 with diseases and symptoms. Sheet2 and Sheet3 were entirely blank. And tell me where you want the cell with the breed list....

  10. #10
    Registered User
    Join Date
    02-13-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Finding text in column B, then copying corresponding value from column A into new shee

    I will try to attach the full version - thanks for being patient with me.

    Example.xlsx
    Attached Files Attached Files

  11. #11
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,302

    Re: Finding text in column B, then copying corresponding value from column A into new shee

    That is the same file - only one sheet, with diseases and symptoms but no breed information.

  12. #12
    Registered User
    Join Date
    02-13-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Finding text in column B, then copying corresponding value from column A into new shee

    Example_sheet2.xlsxGood morning!
    I am not sure why it isn't loading the second sheet. I will save that as an individual file and see if that provides the information...

  13. #13
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,302

    Re: Finding text in column B, then copying corresponding value from column A into new shee

    None of those diseases listed are found on the first sheet. Will that be typical? Or is there always a match? (Acne, kidney disease...?)

  14. #14
    Registered User
    Join Date
    02-13-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Finding text in column B, then copying corresponding value from column A into new shee

    Book2.xlsx

    Hi Bernie,
    I apologize for the difficulty in loading the excel sheet - it isn't saving it as an excel sheet for some reason but rather as a word file. Is this working now?

  15. #15
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,302

    Re: Finding text in column B, then copying corresponding value from column A into new shee

    Try this file.
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    02-13-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Finding text in column B, then copying corresponding value from column A into new shee

    THAT WORKED!!!!! THANK YOU SO VERY, VERY, VERY MUCH!!!!!!!!!!!!!!!!!!!!! I am so grateful to you for your help. Can I pay you somehow for your help?

  17. #17
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,302

    Re: Finding text in column B, then copying corresponding value from column A into new shee

    Quote Originally Posted by antibudger View Post
    THAT WORKED!!!!! THANK YOU SO VERY, VERY, VERY MUCH!!!!!!!!!!!!!!!!!!!!!
    Great!

    Can I pay you somehow for your help?
    No - but thanks for thinking that way
    Bernie Deitrick
    Excel MVP 2000-2010

+ 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. Extracting specific text from a column and copying to another sheet or workbook
    By Noobcake in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-04-2013, 09:29 AM
  2. Replies: 6
    Last Post: 04-12-2013, 01:02 PM
  3. [SOLVED] Finding data in column a copying to entire row to new sheet
    By ALLEYCAT38 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-05-2012, 04:52 PM
  4. [SOLVED] copying specific certain column data based on cell/column value to another sheet
    By arctic7 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-09-2012, 03:38 PM
  5. Replies: 4
    Last Post: 11-30-2009, 07:11 AM

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