+ Reply to Thread
Results 1 to 10 of 10

Search and return data from a row in one sheet to every other row in a column in another

  1. #1
    Registered User
    Join Date
    07-23-2014
    Location
    USA
    MS-Off Ver
    Windows 7
    Posts
    23

    Search and return data from a row in one sheet to every other row in a column in another

    I have data in a table in sheet2, and I have a field on sheet 1 to enter the Record Id as a search criteria, and based on the Type associated with the record id used in the search I want to to find and return specific colums from the associated row in sheet 2 to sheet1 column c every other row. For example, lets say I have a table like the below (actual has around 40 columns) on sheet 2:

    RECORDID TYPE COAT COLOR TEMPERMENT FOOD
    12345 Bird Feather Blue Fun Seeds
    12346 Cat fur Tiger Grouchy Chicken
    12347 Dog fur Black Friendly Beef
    12348 Fish Scale Gold Fun Flakes

    If I enter 12345 I want to return data from that row to sheet1 as follows:
    cell c3 = 12345
    cell c5 = Bird
    cell c7 = Feather
    cell c9 = Blue
    cell c11 =
    cell c13 = Seed

    If I enter 12345 I want to return data from that row to sheet1 as follows:
    cell c3 = 12345
    cell c5 = Cat
    cell c7 =
    cell c9 = Tiger
    cell c11 =
    cell c13 =

    Where there is nothing after the equal means that information should not be carried over to sheet1; i.e. for record 12345 the temperment (fun) should not be carried over to sheet1, and for record 12346 the coat (fur), temperment (groughy) and food (chicken) should not be carried over to sheet1.
    As indicated, the actual sheet has about 50 columns in sheet2 and only values from specific columns based on the TYPE column for the selected record id should be brought over to sheet1.

    The number of records on sheet2 is dynamic and will change.

    Any ideas on the best way to do this

    Thanks Seeki
    Last edited by Seeki; 08-05-2015 at 12:58 AM.

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: Search and return data from a row in one sheet to every other row in a column in anoth

    To best describe or illustrate your problem you would be better off attaching a dummy workbook. The workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    To attach a file to your post,
    click advanced (next to quick post),
    scroll down until you see "manage file",
    click that and select "add files" (top right corner).
    click "select files" find your file, click "open" click "upload" click 'done" bottom right. click "submit reply"

    Once the upload is completed the file name will appear below the input boxes in this window.
    You can then close the window to return to the new post screen.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Expert
    Join Date
    11-26-2013
    Location
    Colac, Victoria, Australia
    MS-Off Ver
    Excel 2016
    Posts
    1,309

    Re: Search and return data from a row in one sheet to every other row in a column in anoth

    Hi Seeki,

    You really didn't supply enough information, as I have no idea what is on the empty alternate rows. I have assumed they are blank.

    I have also assumed that you have the HEADINGS from Sheet 2 in Column B on Sheet 1.

    In the attached,I have used a Named Range (dRange) for dynamic range as follows: =OFFSET(Sheet2!$A$1,0,0,COUNTA(Sheet2!$A:$A),COUNTA(Sheet2!$1:$1))

    Then in column C, the formula =IF(VLOOKUP($C$1,dRange,COUNTA($B$3:B3),0)=0,"",VLOOKUP($C$1,dRange,COUNTA($B$3:B3),0)) looks up the appropriate values.

    Best I can do with the information provided. If you want more, please post a sample workbook!

    I hope this helps, please let me know!

    Regards,

    David

    Please remember, your request is clearer if you attach a sample workbook.
    - Click on Go Advanced and click on the Paper Clip.

    If this has been of assistance, please advise. A little thanks goes a long way.
    - Please click on the *Add Reputation button at the bottom of helpful responses.

    Please mark your thread as SOLVED:
    - Click Thread Tools above your first post, select "Mark your thread as Solved".

    If several people have responded, when you reply please make it clear WHO you are responding
    to by mentioning their name.
    Attached Files Attached Files

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Search and return data from a row in one sheet to every other row in a column in anoth

    Make use of excel built-in features and make it a real ExcelTable (Ribbon: Insert - Table).

    And why not use IFERROR instead of double statement in formula ?

  5. #5
    Forum Expert
    Join Date
    11-26-2013
    Location
    Colac, Victoria, Australia
    MS-Off Ver
    Excel 2016
    Posts
    1,309

    Re: Search and return data from a row in one sheet to every other row in a column in anoth

    Quote Originally Posted by bakerman2 View Post
    And why not use IFERROR instead of double statement in formula ?
    Thought of that, but I didn't get an error. The vlookup returned a ZERO. Seeki wanted the cell to be blank.

    DAC

  6. #6
    Registered User
    Join Date
    07-23-2014
    Location
    USA
    MS-Off Ver
    Windows 7
    Posts
    23

    Re: Search and return data from a row in one sheet to every other row in a column in anoth

    Thanks again for replying. The below is the VBA code that I am using to get what I needed. I was able to create it after watching a few youtube videos by Dinesh Kumar Takyar. None specifically address what I needed but I was able to tweak the information from his videos to meet my need.

    Please Login or Register  to view this content.
    Last edited by Seeki; 08-08-2015 at 01:50 AM.

  7. #7
    Forum Expert
    Join Date
    11-26-2013
    Location
    Colac, Victoria, Australia
    MS-Off Ver
    Excel 2016
    Posts
    1,309

    Re: Search and return data from a row in one sheet to every other row in a column in anoth

    Hi Seeki,

    Are you saying that the code you posted has resolved your problem, or are you asking about the code? It could certainly be made a LOT shorter!

    Regards,

    David

  8. #8
    Registered User
    Join Date
    07-23-2014
    Location
    USA
    MS-Off Ver
    Windows 7
    Posts
    23

    Re: Search and return data from a row in one sheet to every other row in a column in anoth

    Hi David,

    Thanks for following up. The code I posted IS working for me, so yes it has resolved my problem. However, since you indicated it could be a lot shorter, I would be interested in knowing how to make it shorter.

    Basically I created a form using cells in excel (not userform) by locking all cells except the ones I am using for data entry. Some of the data entry cells are conditionally locked and gray to limit entry of data based on value user selected in the very first cell in the form. The information entered in the form is saved to another sheet in the workbook. This code is to pull back a record from the saved information based on a criteria entered in cell H3 of the data entry form. Hence the multiple segments in my code. If it can be made shorter I am definitely interested in knowing how.

  9. #9
    Forum Expert
    Join Date
    11-26-2013
    Location
    Colac, Victoria, Australia
    MS-Off Ver
    Excel 2016
    Posts
    1,309

    Re: Search and return data from a row in one sheet to every other row in a column in anoth

    Hi Seeki,

    I can't test this as I don't have a workbook, but here is a small slice of your code to give you an idea.

    1. I have declared two worksheets (ws1 and ws2) and Set them to be equal to Sheets1 and 2. From then on, you can refer to them as ws1 and ws2 instead of Sheets("sheet1"). Saves a lot of time.
    2. Instead of assigning a value to every cell, I used a loop. The macro just cycles around 19 timed, incrementing the address by 1 or 2.

    NOTE: This is not complete - just to give you an idea if how to create more efficient code. Have a go, and if you get into difficulty, post a copy of your workbook (or a desensitized sample).

    Please Login or Register  to view this content.
    I hope this helps, please let me know!

    Regards,

    David


    - Please click on the *Add Reputation button at the bottom of helpful responses.

    Please mark your thread as SOLVED:
    - Click Thread Tools above your first post, select "Mark your thread as Solved".

    If several people have responded, when you reply please make it clear WHO you are responding
    to by mentioning their name.

  10. #10
    Registered User
    Join Date
    07-23-2014
    Location
    USA
    MS-Off Ver
    Windows 7
    Posts
    23

    Re: Search and return data from a row in one sheet to every other row in a column in anoth

    Hi David,
    Tested it and it works. Thanks, much appreciated!

+ 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 sheet colums and return data
    By MrGuard2015 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-30-2015, 09:56 AM
  2. Replies: 3
    Last Post: 07-17-2013, 03:41 AM
  3. Search Code vba return to the new sheet with duplicate data
    By tantcu in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-27-2013, 06:28 PM
  4. [SOLVED] Search Column for text, Return Cell below to another sheet?
    By Dewy1425 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-01-2012, 08:07 PM
  5. Search column and return data to another worksheet.
    By LaurenR in forum Excel General
    Replies: 7
    Last Post: 12-10-2010, 05:18 PM
  6. Search a column of dates & return data from another column
    By headscratching in forum Excel General
    Replies: 6
    Last Post: 06-09-2009, 07:34 PM
  7. Replies: 4
    Last Post: 06-07-2009, 10:55 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