+ Reply to Thread
Results 1 to 17 of 17

Userform to copy data from one sheet to another

  1. #1
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Userform to copy data from one sheet to another

    Hello everyone,

    The added workbook has an example.

    On Sheet2 I would like to have a botton which opens a form which has to ask for an input.
    This input has to be compared with entries on Sheet1 in column A. If they match it should copy the data from Sheet1 to Sheet2.
    But not all data, only the data in column C: Input2. If it doesn't match it should give an error message and the option to either try again or cancel.

    I hope you can help me with this!
    Also, I would like to request the apostrophe notes with the code so it's easier for me to understand what is going on.

    Thanks in advance,

    Kind regards,

    Marco
    Attached Files Attached Files
    Last edited by Marco-Kun; 12-13-2011 at 10:58 AM. Reason: Removed a spelling error

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Userform to copy data from one sheet to another

    Hi Marco-Kun
    So, based on your sample file, if the user entered Example3 on the UserForm, Sheet2 would have Example3 in Cell A2 and 8 in Cell B2? If true...what happens on the next selection...should Sheet2 be cleared before adding the next selection?
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Userform to copy data from one sheet to another

    Hello jaslake,

    Quote Originally Posted by jaslake View Post
    Hi Marco-Kun
    So, based on your sample file, if the user entered Example3 on the UserForm, Sheet2 would have Example3 in Cell A2 and 8 in Cell B2?
    That is correct.

    Quote Originally Posted by jaslake View Post
    If true...what happens on the next selection...should Sheet2 be cleared before adding the next selection?
    No Sheet2 shouldn't be cleared, that entry should be placed below the last entry.

    Marco

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Userform to copy data from one sheet to another

    Hi Marco
    I've attached a copy of your workbook that includes code to use either a ComboBox or a ListBox (use one or the other...not both). The first thing I did was created a Dynamic Named Range...see this link http://www.ozgrid.com/Excel/DynamicRanges.htm

    You can see the Named Range and it's definition by clicking on Formulas --> Name Manager --> Examples and you'll see it's defined as
    Please Login or Register  to view this content.
    This makes the Named Range dynamic...as you add items to Sheet1, Column A they'll be added to the Named Range.

    The code is fully commented...if you have issues, please let me know.
    Attached Files Attached Files

  5. #5
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Userform to copy data from one sheet to another

    Hello jaslake,

    Thank you very much for your reply, and for your great help!
    The example you added works perfectly. Also thank you for the comments added to the code, that really helps me a lot.
    So, if I understand correctly, if I add the following rule to the code, it will also copy the value in column C from Sheet1?

    Please Login or Register  to view this content.
    Another question: What code has to be changed if the values which has to be copied needs to be pasted in a table on Sheet2?

    For example, I have 2 tables on Sheet2, Table1 and Table2. How do I refer to the table in the code for the values to be pasted in?

    Thank you! Will add reputation to your last post.

    Kind regards,

    Marco

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Userform to copy data from one sheet to another

    Hi Marco
    If I understand your question correctly
    if I add the following rule to the code, it will also copy the value in column C from Sheet1?
    I'd think you'd want this code
    Please Login or Register  to view this content.
    Regarding this question
    What code has to be changed if the values which has to be copied needs to be pasted in a table on Sheet2?

    For example, I have 2 tables on Sheet2, Table1 and Table2. How do I refer to the table in the code for the values to be pasted in?
    Tables are a different animal (if you truly are referring to Tables). Tables are NOT a normal worksheet. I have worked with Tables and can help with that. I'm not expert with them and would need to see your actual workbook with a description of what you wish to do.

  7. #7
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Userform to copy data from one sheet to another

    Hello jaslake,

    Ah, of course. I forgot to edit the column range in the code as well.

    I added an example workbook with two Tables on Sheet2. You can see the both of them in the Name Manager as well.

    So for example, if I want the values to be copied to Table2, the code will already work as it's looking for the last row, which happens to be Table2. But what if I want it to copy to Table1? How can that be done? Can the VBA code refer to a Table name?

    I hope this will make it somewhat more clear.

    Kind regards,

    Marco
    Attached Files Attached Files

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Userform to copy data from one sheet to another

    Hi Marco

    I'd need to know much more of what you're trying to do but the attached seems to update your tables as required. The ComboBox procedure updates Table1...the ListBox procedure updates Table2. They're interchangeable...simply change the Table Reference.
    Attached Files Attached Files

  9. #9
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Userform to copy data from one sheet to another

    Hello jaslake,

    As far as I tested it, it works exactly as I wanted. I wanted a code which could give me the option to, if needed, change Table to insert the data too.
    Sot this code works perfectly:
    Please Login or Register  to view this content.
    At the moment I'm testing it with my original workbook, I will come back in a moment.
    I have one question though. How do I move the buttons you made? I have another kind of button which I can move by clicking on it while holding the CTRL button. Doesn't seem to work for these ones.

    Thanks a lot for your help!

    Kind regards,

    Marco

  10. #10
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Userform to copy data from one sheet to another

    Hi Marco

    To do this
    How do I move the buttons you made
    Go into design Mode on the Developer Tab then place the Mouse over the button...with the left mouse button depressed, drag the Button to it's new location. Exit Design Mode.

  11. #11
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Userform to copy data from one sheet to another

    Thank you very much. I first had to activate the Developer Tab though.

    Another question. I didn't think of this before because I thought it maybe would already happen; but is it possible to also copy any comments added to a cell to the new sheet?

    Marco

  12. #12
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Userform to copy data from one sheet to another

    Hi Marco
    Play with the code in the attached. I've added a couple of comment tags in Sheet1. I only modified the code for the ComboBox but the same can be applied to the ListBox code. Let me know of issues.
    Attached Files Attached Files

  13. #13
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Userform to copy data from one sheet to another

    Hello John,

    Thanks for all your help! That works perfectly. I can play with the code and use it for the ListBox function as well.

    Marco

    [SOLVED]

  14. #14
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Userform to copy data from one sheet to another

    Hi Marco
    You're welcome...glad I could be of help. If that satisfies your need, I'd appreciate it if you'll please mark your thread as "Solved".

    To mark your thread solved do the following:
    - Go to your first post on the thread
    - Click edit
    - Click Advance
    - Just below the word "Title:" you will see a dropdown with the word No prefix.
    - Change to Solved
    - Click Save

  15. #15
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Userform to copy data from one sheet to another

    Hello John,

    Yes, you were a great help. I know how to mark it as [SOLVED] but I found something.

    The comments do indeed copy, if it's a comment with text. However, if a comment has a picture, it won't copy.
    It will only make an empty comment on Sheet2.

    Kind regards,

    Marco
    Last edited by Marco-Kun; 12-12-2011 at 10:53 AM.

  16. #16
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Userform to copy data from one sheet to another

    Hi Marco

    Try this code...I've tested it but not thoroughly
    Please Login or Register  to view this content.
    Let me know of issues.

  17. #17
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Userform to copy data from one sheet to another

    Hello John,

    Thank you very much! That works like I wanted it to work. Now I will mark it as [SOLVED].

    Kind regards,

    Marco

+ 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