+ Reply to Thread
Results 1 to 31 of 31

Macro for searching on sheet 1 with data from sheet 2 and create new sheets

  1. #1
    Registered User
    Join Date
    01-31-2014
    Location
    St. Pete, FL
    MS-Off Ver
    Excel 2010
    Posts
    36

    Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    Ok here is my issue, I get excel files listing of clients that need to be updated. We have assigned reps for each client. So what I have created was a workbook with a list of our reps with their client ids example:

    Sheet1
    client lists for updates/changes

    Sheet2
    REP | REP | REP | REP
    id# | id# | id# | id#
    id# | id# | id# | id#

    Sheet2 has a list from A-I

    What I want is if any data in sheet1 matches the list for Rep A it will copy the entire row(s) from sheet1 and create a new sheet for just that rep on the new sheet. Same for rep B,C,Etc. so on.

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    Can you attach a file with some sample data? To attach a file, push the button with the paperclip (or scroll down to the Manage Attachments button), browse to the required file, and then push the Upload button.

  3. #3
    Registered User
    Join Date
    01-31-2014
    Location
    St. Pete, FL
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    And a note, I know nothing about vba or creating macros.

  4. #4
    Registered User
    Join Date
    01-31-2014
    Location
    St. Pete, FL
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    SAMPLE.xlsm here is a sample, keep in mind, client ids list is not always in the same columns which is why i would like to search the entire sheet 1 for the ids. the sample on sheet 1 is only a fraction of the actual data I receive btw. :-)
    Last edited by stitchoz; 02-28-2014 at 11:08 AM.

  5. #5
    Registered User
    Join Date
    01-31-2014
    Location
    St. Pete, FL
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    I've attached a sample

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    Try it on your sample file too see if it does what you want.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    01-31-2014
    Location
    St. Pete, FL
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    Quote Originally Posted by JOHN H. DAVIS View Post
    Try it on your sample file too see if it does what you want.
    That works great if the client IDs are always in row B, but what if for example I get a sheet that has the client IDs listed in another row like A, C, D, etc.?

  8. #8
    Registered User
    Join Date
    01-31-2014
    Location
    St. Pete, FL
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    On another note, my lists generally are at least 200 rows long up to over 1000. I noticed this only scanned the first few lines on the sample, what would i need to change to use this on my actual list?

  9. #9
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    Quote Originally Posted by stitchoz View Post
    That works great if the client IDs are always in row B, but what if for example I get a sheet that has the client IDs listed in another row like A, C, D, etc.?
    It searches Sheet2 regardless of which Column? It searches Sheet1 Column B. There has to be someway to tells what is a client ID and what is not if Sheet1 Column B is not the Column which has the IDs.

  10. #10
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    Quote Originally Posted by stitchoz View Post
    On another note, my lists generally are at least 200 rows long up to over 1000. I noticed this only scanned the first few lines on the sample, what would i need to change to use this on my actual list?
    It searchs from row2 to the last row with data, so that shouldn't be a problem.

  11. #11
    Registered User
    Join Date
    01-31-2014
    Location
    St. Pete, FL
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    Quote Originally Posted by JOHN H. DAVIS View Post
    It searches Sheet2 regardless of which Column? It searches Sheet1 Column B. There has to be someway to tells what is a client ID and what is not if Sheet1 Column B is not the Column which has the IDs.
    Ok, so if for example the client ID is in column C, instead of B. Where in the macro would I change that information?

  12. #12
    Registered User
    Join Date
    01-31-2014
    Location
    St. Pete, FL
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    Quote Originally Posted by JOHN H. DAVIS View Post
    It searches Sheet2 regardless of which Column? It searches Sheet1 Column B. There has to be someway to tells what is a client ID and what is not if Sheet1 Column B is not the Column which has the IDs.
    Would this work?

    Please Login or Register  to view this content.

  13. #13
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    Should work.

  14. #14
    Registered User
    Join Date
    01-31-2014
    Location
    St. Pete, FL
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    Quote Originally Posted by JOHN H. DAVIS View Post
    It searchs from row2 to the last row with data, so that shouldn't be a problem.
    It only pulls 1 record from sheet1 and creates it onto the new sheet, not all of them. So for example there is 5 of them on sheet 1 for that pertains to rep1 from sheet 2, I need it to be able to pull all 5 onto that new sheet, not just 1. I hope I'm making sense of what I'm trying to do. I apologize to be ignorant on how vba works. I know that the sample was only a very small list, but the original has over 100 entries. trying to divide them up by rep without having to look them up individually in our system.
    Last edited by stitchoz; 02-28-2014 at 03:13 PM.

  15. #15
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    Modified:

    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    01-31-2014
    Location
    St. Pete, FL
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    That worked perfectly! But I do have one thing, even though it worked perfect I did get a vb error "Run-time error '91' Object variable or With block variable not set" Should I just ignore and hit end when I run this macro or is there way so the error doesn't pop up. Other than that, it worked exactly how I need it to, I really do appreciate the amount of time you took out for this to help me!

  17. #17
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    I can't find anything that would cause that error. And if it did then the macro should have stopped. Can you post your code exactly as you have it?

  18. #18
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    Try:

    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    01-31-2014
    Location
    St. Pete, FL
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    I copied the code per your modified, here is the file I'm working with. You can ignore the unnamed sheets unless there is a way to where it only creates for just the reps I have listed in sheet 2. Tx rate changes.xlsm

    code:

    Please Login or Register  to view this content.

  20. #20
    Registered User
    Join Date
    01-31-2014
    Location
    St. Pete, FL
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    This is the original without the macrotx client list.xlsx

  21. #21
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    The code you post in Post19 is not the modified version.

    Try this:

    Please Login or Register  to view this content.

  22. #22
    Registered User
    Join Date
    01-31-2014
    Location
    St. Pete, FL
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    Error was gone, but now its not pulling all the data onto new sheets correctly like before.

    No error but not copying and pastings all the data
    Please Login or Register  to view this content.
    with error but pulls all the data correctly
    Please Login or Register  to view this content.
    From reading up on the error it appears to be something with the set, object or reference?
    Last edited by stitchoz; 02-28-2014 at 05:25 PM.

  23. #23
    Registered User
    Join Date
    01-31-2014
    Location
    St. Pete, FL
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    Ok I think I got a general idea what the error is, I think its because of how sheet 2 is structured is causing that error. The lists length is uneven, which might causing that error from column A stops, but the others have more beyond what column A has. So what if it gets recreated to have the rep name in the rows and the client ids in the columns. Is this very possible to be the cause?
    Or that I'd have to rebuild sheet2 to have column A rep, column B client ID, and repeat it. Like this:
    Rep1 id
    Rep1 id
    Rep1 id
    Rep2 id
    Rep2 id

    But that is a lot of work to do it like that. But that is what someone had suggested possible that may be the cause.
    Last edited by stitchoz; 02-28-2014 at 05:42 PM.

  24. #24
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    Is this it?

    Please Login or Register  to view this content.

  25. #25
    Registered User
    Join Date
    01-31-2014
    Location
    St. Pete, FL
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    Still same issue, it works but gives the error in the same area of the code. Do you think it may be because of the unknown client IDs? Maybe if somewhere it could only pull what is on the sheet2 list, and for what is on sheet1 that isn't on sheet2 to ignore those values?

  26. #26
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    Quote Originally Posted by stitchoz View Post
    Still same issue, it works but gives the error in the same area of the code. Do you think it may be because of the unknown client IDs? Maybe if somewhere it could only pull what is on the sheet2 list, and for what is on sheet1 that isn't on sheet2 to ignore those values?
    I'm sorry, but I don't receive any error from the code I posted in Post#24? I used in on the last example you provided. No issues at all?

  27. #27
    Registered User
    Join Date
    01-31-2014
    Location
    St. Pete, FL
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    I have edited the Rep List to be all listed in columns A with the name and B with the ID on sheet 2. Maybe with it setup this way it will not occur with the error. Here is a copy without any macros on it, possible to see if this works with the macros?
    Attached Files Attached Files

  28. #28
    Registered User
    Join Date
    01-31-2014
    Location
    St. Pete, FL
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    Quote Originally Posted by JOHN H. DAVIS View Post
    I'm sorry, but I don't receive any error from the code I posted in Post#24? I used in on the last example you provided. No issues at all?
    The sample sheet doesn't generate any errors, its when I use it on the full scale one that it does.

  29. #29
    Registered User
    Join Date
    01-31-2014
    Location
    St. Pete, FL
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    Scratch that, it did work, I'm not sure what I did wrong the first time.

  30. #30
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    Quote Originally Posted by stitchoz View Post
    The sample sheet doesn't generate any errors, its when I use it on the full scale one that it does.
    I wouldn't be able to tell? I'm afraid I can't offer much else.

  31. #31
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Macro for searching on sheet 1 with data from sheet 2 and create new sheets

    Quote Originally Posted by stitchoz View Post
    Scratch that, it did work, I'm not sure what I did wrong the first time.
    If it is working, please comply with Forum Rule No. 9.

    9. Acknowledge the responses you receive, good or bad. If your problem is solved, please say so clearly, and mark your thread as Solved: Click Thread Tools above your first post, select "Mark your thread as Solved". Or click the Edit button on your first post in the thread, Click Go Advanced, select [SOLVED] from the Prefix dropdown, then click Save Changes. If more than two days have elapsed, the Dropdown option or Edit button will not appear -- ask a moderator to mark it.

+ 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: 1
    Last Post: 12-03-2013, 04:19 AM
  2. Macro: Create an input sheet an copy the data onto a new row in another sheet
    By bernardnoel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-17-2013, 09:23 AM
  3. How to create Macro For 100 sheet data into one master sheet
    By datta9381 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-24-2012, 04:59 AM
  4. Searching for data across multiple sheets and copying to one main sheet
    By truedonk in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-24-2008, 08:13 AM
  5. Macro to create new sheets from master data sheet
    By adsigel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-04-2006, 09:21 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