+ Reply to Thread
Results 1 to 12 of 12

Grabbing data from one sheet and displaying on another?

  1. #1
    Registered User
    Join Date
    10-15-2008
    Location
    Chicago, IL
    Posts
    7

    Grabbing data from one sheet and displaying on another?

    Hi all,

    I am seeking a method of collecting data from one sheet in a workbook and displaying it on another, based on a search.

    e.g.

    Sheet1
    Garcia Joe 11111
    Garcia Matt 22222
    Hernandez Efrain 33333
    Matias Jorge 44444

    What I want to do is to have Sheet2 be a query for Sheet1--that is, in a cell in Sheet2, the user can type 'Garcia' into a cell and thus display the matching entries from Sheet1, e.g.

    Sheet2
    'Garcia' displays

    Garcia Joe 11111
    Garcia Matt 22222

    I don't know if this can be done purely within Excel or if I'll need a VB macro to do it, any help would be greatly appreciated.

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606
    You can do it with a formula - here is one approach. If your data are in A1:A4 on sheet1 and search item in A1 in sheet2, then results are in A2 downwards of sheet2:

    A2 down, entered with Ctrl+Shift+Enter
    =IF(COUNTIF(Sheet1!$A$1:$A$4,Sheet2!$A$1&"*")<ROWS(A$2:A2),"",INDEX(Sheet1!$A$1:$A$4,SMALL(IF(ISNUMBER(FIND($A$1,Sheet1!A$1:A$4)),ROW(Sheet1!A$1:A$4)-ROW(Sheet1!A$1)+1),ROWS(A$2:A2))))

    It will need slight tweaking if you wanted to search for strings contained within cells rather than at the beginning.

    You could do it with VBA too.

  3. #3
    Registered User
    Join Date
    10-15-2008
    Location
    Chicago, IL
    Posts
    7
    Quote Originally Posted by StephenR View Post
    You can do it with a formula - here is one approach. If your data are in A1:A4 on sheet1 and search item in A1 in sheet2, then results are in A2 downwards of sheet2:

    A2 down, entered with Ctrl+Shift+Enter
    =IF(COUNTIF(Sheet1!$A$1:$A$4,Sheet2!$A$1&"*")<ROWS(A$2:A2),"",INDEX(Sheet1!$A$1:$A$4,SMALL(IF(ISNUMBER(FIND($A$1,Sheet1!A$1:A$4)),ROW(Sheet1!A$1:A$4)-ROW(Sheet1!A$1)+1),ROWS(A$2:A2))))

    It will need slight tweaking if you wanted to search for strings contained within cells rather than at the beginning.

    You could do it with VBA too.
    Thanks StephenR,

    unfortunately I can't get this to work, even on my example data set above; I'm not sure what's going wrong.

    In VBA, how could I do this? I think, with my limited programming knowledge, it might be as simple as defining an array, calling the Index worksheet function to populate the array, and then transposing the array into the cells I want the data to appear in.

    But I am very unsure of methodology, if my logic is sound, and all that.

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606
    See attachment for an example of the formula. Note the curly brackets round the formula -they don't appear if you don't enter it correctly and that may be the problem.

    Have also added a VBA approach, which uses the Find method - press the button.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    10-15-2008
    Location
    Chicago, IL
    Posts
    7
    Quote Originally Posted by StephenR View Post
    See attachment for an example of the formula. Note the curly brackets round the formula -they don't appear if you don't enter it correctly and that may be the problem.

    Have also added a VBA approach, which uses the Find method - press the button.
    Hi, StephenR,

    Thanks; the VBA approach looks like what I want. Here's another question for you--how can I alter the ranges and such to point towards the area of data I actually want it to reference?

    In this case, the sheet with the data is Sheet4 (named within Excel as 'master_list_by_name') and the query sheet is Sheet2 (named Query), and the range of cells we want to search is A1 to A5000.

    I tried making outright substitutions but it doesn't seem to be working---and my apologies, it's been busy as heck around the office and this is actually something of a side project.

  6. #6
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606
    Probably easiest if you attach a small sample of your data, but in the meantime try this:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    10-15-2008
    Location
    Chicago, IL
    Posts
    7
    Here's a small sample, including the query page--ideally the data should display from A12 downwards.
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561
    I'd recommend a pivot table.
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    05-26-2008
    Posts
    122
    im trying to do something similar.. i found this thread to be helpful


    http://www.excelforum.com/excel-prog...directory.html

    the only thing is it doesnt do partial searches..

  10. #10
    Registered User
    Join Date
    10-15-2008
    Location
    Chicago, IL
    Posts
    7
    Quote Originally Posted by StephenR View Post
    Probably easiest if you attach a small sample of your data, but in the meantime try this:
    Please Login or Register  to view this content.
    Hi StephenR,

    Hoping you're still willing to help me out here. I tinkered with the code as much as I was able and have managed a /few/ small successes but nothing remotely resembling what I want. (Given the difficulty I've had in accomplishing what sounds, on the surface, to be simple, I'm hardly surprised.)

    Using my sheet, with the input in B9 and display to show from A12 downwards, I have managed to have the VBA script lay out from A12 down--however, it pastes only the last name, not the entire row, and it pasted it for approximately 2000 rows, the last time I tried it, rather than the number of rows corresponding to the number of entries for the name.

    Here is the code as it looks now:
    Please Login or Register  to view this content.

  11. #11
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606
    Yes, I'll have a look. I don't have Excel 2007 so wasn't able to look at your attachment. I can access it tomorrow, or post an Xl2003 file.

    EDIT: does this work for you? (I'm not sure which is the barcode column.)
    Please Login or Register  to view this content.
    Last edited by StephenR; 10-30-2008 at 06:40 AM.

  12. #12
    Registered User
    Join Date
    10-15-2008
    Location
    Chicago, IL
    Posts
    7
    Quote Originally Posted by StephenR View Post
    Yes, I'll have a look. I don't have Excel 2007 so wasn't able to look at your attachment. I can access it tomorrow, or post an Xl2003 file.

    EDIT: does this work for you? (I'm not sure which is the barcode column.)
    Please Login or Register  to view this content.
    Wow! That works perfectly. Thank you very much, Stephen. I was just about going insane trying to figure this out.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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