Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13

Thread: Help with Macro: finding and copying data between worksheets

  1. #1

    Help with Macro: finding and copying data between worksheets



    Register for a FREE account, and/
    or Log in to avoid these ads!

    I'm working on a project for an extracurricular I'm involved in that requires manipulating a large Excel sheet with personal information of members. I'm only literate in the basics of Excel, but I really need help making a macro to automate the transfer of data for this project.


    Basically, I have two worksheets, one with member names and blank contact info, and the other with names and contact info filled in. I need some way of automating the following:



    1. Search for each listed name in the blank document
    2. Copy the associated contact information from the completed doc to the blank doc




    One issue is that the name format for the two documents is different, unfortunately. The blank doc has a column with full names (first middle last, suffix), the doc with contact info is formatting with three name columns: (first MI last), (suffix), and (last name). There are definitely non-unique last names.


    I'm a newbie when it comes to macros and VBA, so hopefully you all can lend me a helping hand! Please let me know if you need more detail information. I can post a blank copy of the worksheets if necessary.


    Thanks,
    Neal

  2. #2
    Attached the data. Essentially, the "Needs Contacts" document doesn't even need to be formatted as such (only thing that matters is the Name column), I would be just as happy to automate the process of finding each name in "Needs Contacts" and coping all cells for that name from the "Has Contacts" to the doc without contact info.
    Attached Files Attached Files

  3. #3
    Magician Hercules1946's Avatar
    Join Date
    Mar 2013
    Location
    York, England
    Posts
    779
    Articles
    0
    Excel Version
    2010
    Hello
    This could be a difficult task, as when people are entering text, they are inevitably inconsistent, prone to typing errors, mis-spelling etc. This is why its common practice to allocate a code rather than just use the name, especially where you are dealing with a lot of people. After all, with a common name, You could find two people called (e.g.) John Smith.
    Looking at your (few) examples, there is a consistency in the two tables, in that each name starts with a matching value, and each also finishes with a matching value. As a result an algorithm based on that would match these examples correctly. Your first aim should be to insert the correct name from the "Has Contacts" into an extra column in the "Needs Contacts", so that this can be used to look up the correct row in "Has Contacts" to transfer across the correct contact data. Going forward I would recommend that you try to establish if these persons already have a coding system that you could adopt, or alternatively get them to use the same source for the names.
    Take a look at your data overall, and see if you think in the immediate my idea would solve the problem, and then we can devise a suitable formula to match the first and last characters.

  4. #4
    Thanks for your reply, Hercules. Your idea about assigning a unique code to each person certainly would have made me life a lot easier, however it's basically to late. Neither list is going to change/update drastically in the future, but if you think assigning codes to each existing person would help solve my problem (and not create a separate problem), then I'm open to suggestions on how to accomplish that. Having the codes may end up being helpful in the future if I have to manipulate these tables again.

    Your idea about using an algorithm to match the first and last couple of values is great, and I think would work perfectly! Please let me know if you need a more detailed sample sheet than the one I provided, since it has relatively few names.

    Thanks again!

  5. #5
    Magician Hercules1946's Avatar
    Join Date
    Mar 2013
    Location
    York, England
    Posts
    779
    Articles
    0
    Excel Version
    2010
    I don't need any more data at the moment, provided its safe to assume that the majority follows the matching pattern we have identified. There may be some exceptions when we build the extra "key" column and we will need to sort those out manually.
    I will get back to you a little later, I don't have a library of "off the shelf" formulae to reference.

  6. #6
    Magician Hercules1946's Avatar
    Join Date
    Mar 2013
    Location
    York, England
    Posts
    779
    Articles
    0
    Excel Version
    2010
    Hello Simsmac
    Sorry Ive been delayed a little. I hope the attachments will do what you need for a high percentage of the records. I couldn't relate the columns across the two workbooks, so Ive just added some to the "Needs" book, and populated them from the "Has" book.
    Adjust the columns and the dimensions of the table array as required/to suit your data set. Make sure you load both workbooks.
    Attached Files Attached Files

  7. #7
    This is amazing! Thank you so much. Lastly, I'm trying to implement this into the actual documents, but when I copy the formulas that refers to the "Has Contacts" document into my actual document, it gives me an error. I changed the formula to refer to the actual name of my "Has" document, but it says "Value not available error" and N/A for the contact info cells. Like I said, excel is not my forte. Any suggestions?

  8. #8
    Magician Hercules1946's Avatar
    Join Date
    Mar 2013
    Location
    York, England
    Posts
    779
    Articles
    0
    Excel Version
    2010
    Hello simsmac
    Its difficult transporting workbooks that are linked because the location of the (source data) book is recorded by Excel, and this often means that it can't adjust the links automatically when the two books are downloaded to a new location.
    Firstly, can I ask:
    1. You say that you are having problems copying the formulae into your actual document. Looking at the example workbooks I posted (#6), when you load them into your computer, do they show the correct information ?
    2. In the examples you will see that Ive added an extra column in both sheets headed "key", that join together the first and last names. These keys are used to match the records in the two books. Have you managed to add these keys OK in your actual documents? If you have, then make sure that the Key column in the "Has Contacts" book is also the first column in Array table defined in your VLOOKUP formulae. In the example LOOKUP has Cols A to J for the Array Table, and the keys are in Col A of that table. If you don't get that right, the formulae will report errors.

    If checking the above doesn't fix the problems, you will need to give me exact information about your actual documents
    a) Workbook Names
    b) Sheet Names
    c) List of Col Codes and Labels used in each book. (Use the same labels for like data, so I know where to extract from/To.
    d) The columns and the number of rows in the actual "Has Contacts" sheet used for your data.

    I can then work out the correct formulae and post as text for you.
    Last edited by Hercules1946; 2014-09-04 at 09:32 PM.

  9. #9
    I think I have figured out the issue... The formula necessitates that both lists of names are in the exact same order, and that "Has Contacts" doesn't have any names the "Needs Contacts" list does not. If this is indeed the issue, it's my mistake for not creating templates that reflected this. Putting the two documents into the same order is a snap, but I'm guessing the issue will be that the "Has Contacts" list has many names that the "Needs Contacts" list does not.

    I got the formula to work using my document, by making sure the first couple of names are the same and in the same order on my lists, so I know the formula works.

  10. #10
    Magician Hercules1946's Avatar
    Join Date
    Mar 2013
    Location
    York, England
    Posts
    779
    Articles
    0
    Excel Version
    2010
    Hello Simsmac
    It should not matter what order the records are in, or that you have fewer records in the "Needs" workbook. If your formulae are correct and the keys built are unique everything should be OK.
    Can you post the two workbooks as they now are, showing just the following:
    1. Column Labels for each column used. (In the "Needs" book, make sure cols to be taken from "Has" are given the same label as in "has")
    2. In each Book create one example on Row 2 including the formulae you have. Make sure that the First and Last Names in both books are the same, so that the data should extract correctly from "Has" to "Needs".
    3. If you like, give me the number of entries that you have in the real "Has" sheet, so I can dimension the table correctly if you haven't done this. If not I'll make an estimate.

    Don't worry if the formulae don't work. As long as I can understand where everything goes I should be able to fix it.
    Last edited by Hercules1946; 2014-09-05 at 01:09 PM.

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •