+ Reply to Thread
Results 1 to 4 of 4

Custom Copy-Paste Code Help

  1. #1
    Registered User
    Join Date
    10-20-2016
    Location
    Denver, CO
    MS-Off Ver
    Office 2016
    Posts
    7

    Custom Copy-Paste Code Help

    On a Worksheet_Activate event I am looking for a way to copy all items found in a range $C$4:$I$100 (I'll name the range "Parts") to a different worksheet "Part Text", ignoring blanks and duplicates. I would like all items found in the range copied (ignoring blanks and duplicates that may exist in the copied text), but only paste to the "Part Text" worksheet if they do not already exist in the "Part Text" worksheet. I would like them pasted in Column "A" of the "Part Text" worksheet even though they are being copied from multiple columns and rows in the "Parts" range. I would like this to automatically happen when the "Part Text" worksheet is selected (Worksheet_Activate).

    The idea being that when a new part is added to the "Parts" range. If it does not already exist in the "Part Text" worksheet, it will be added to the end of the list in Column "A".

    Is this possible? I appreciate the help.

  2. #2
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    Re: Custom Copy-Paste Code Help

    If I'm understanding your question correctly, I would approach this as a few separate steps...

    First, I'd write a "ForEach" subroutine that takes one column at a time (so first range $C$4:$C$100, then range $D$4:$D$100, etc.) and adds each value found in the given range to the next unused row in column A on a third, hidden worksheet. (May or may not need to be done one column at a time, but that's the easiest way I can think of to make sure it captures all values from all columns in your range and puts them all in a single column.)

    Second, once all the values are gathered into a single column, I would then write code to pull unique values only from the new single column and write those to a new column, either on the same sheet or an additional hidden sheet.

    Once I had a single column containing only the unique values from the original range, I would then write another "ForEach" routine to go row by row and look for a match in your existing list on the "Part Text" sheet, and if no match is found, write the value that did not have a match to the next unused row in column A on sheet "Part Text".


    These three actions should then all be able to be combined into a single subroutine triggered by a Worksheet_Activate event, once each task is working properly on its' own.






    There's probably a simpler, cleaner way to do what you're wanting to do, but that's how I would approach it, being the novice that I am to VBA. I find that it's easier to figure out ways to do complex things by trial and error if I break the complex thing into smaller, less complex things and attack each individually. Hope that helps... If nobody offers a simpler solution, I can try to write some code for this using generic sample data over the next day or two. I'll keep an eye on this thread, and see what I can come up with as time allows.

  3. #3
    Registered User
    Join Date
    10-20-2016
    Location
    Denver, CO
    MS-Off Ver
    Office 2016
    Posts
    7

    Re: Custom Copy-Paste Code Help

    I think I understand your approach. Thanks for the response. I need to digest it and see if I can make this work.

  4. #4
    Registered User
    Join Date
    10-20-2016
    Location
    Denver, CO
    MS-Off Ver
    Office 2016
    Posts
    7

    Re: Custom Copy-Paste Code Help

    I Believe this is what you were talking about. I worked this out today, and it appears to be doing the job. I'm not sure if it is the best way to do it.


    Please Login or Register  to view this content.

+ 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. [SOLVED] Custom Format/Copy-Paste
    By Karen615 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-31-2016, 04:00 PM
  2. [SOLVED] Paste restriction code in vba not affecting GUI copy/paste only Ctrl+V
    By DT211569x in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-25-2016, 01:28 PM
  3. Replies: 0
    Last Post: 10-29-2013, 09:38 AM
  4. Replies: 6
    Last Post: 06-06-2013, 02:06 AM
  5. How to Create a Custom Copy and Paste Function
    By jlmissouri in forum Excel General
    Replies: 2
    Last Post: 01-16-2013, 12:07 AM
  6. [SOLVED] custom button to copy a few cells and paste on somwhere else
    By OMID in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-08-2006, 09:20 AM
  7. Replies: 10
    Last Post: 01-12-2006, 09:55 PM

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