+ Reply to Thread
Results 1 to 8 of 8

Check existing data before copying in new data to avoid duplication

  1. #1
    Forum Contributor
    Join Date
    08-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    132

    Check existing data before copying in new data to avoid duplication

    Hello,

    I cannot figure this out.

    Please Login or Register  to view this content.

    My goal is to do the following:

    1. Scan through each value in column AA from 200 to 2 for the word REMOVE. This works
    2. If I find one, use offset to select that activerow's cell C, the sales order #. This works
    3. Run that sales order number through column C of the RegExpiry tab, to see if it's already in there. This kind of works? maybe?
    4. If it exists - stop, don't copy anything, and go back to the start minus 1 row.
    5. If it doesn't exist, continue on to copy the order into that sheet.

    I'm getting lost with all the IFs and embedded IFs and FORs...

  2. #2
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Check existing data before copying in new data to avoid duplication

    this is a bit confusing without having data to test it on, but try this....

    Please Login or Register  to view this content.
    I can really understand the "getting lost" in IF's and FOR's.....some programmers, including me, when I start a FOR/NEXT or an IF/END IF....I literally start with FOR then type the NEXT X (variable) and then fill in the middle....that way I have on loop construct already built....HTH
    Last edited by judgeh59; 12-06-2013 at 01:04 PM.
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  3. #3
    Forum Contributor
    Join Date
    08-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    132

    Re: Check existing data before copying in new data to avoid duplication

    Thanks for your help!

    You fixed the syntax errors I was having, but the methodology of this is still not functioning correctly.

    When the code gets to this line:

    Please Login or Register  to view this content.
    It says:

    1.) If Cells(6,3).Value = 123456 Then
    2.) Subtract 1 from tRow
    3.) Exit

    1. If Cells(6,3).Value <> 123456
    2. Do copying code.


    This is not what I want it to do.

    I want it to scan - (6,3) then (5,3) then (4,3) etc... If it finds that order# 123456 in ANY of those cells, that means the order is already on the sheet, so I want it NOT to copy that order in. Only AFTER it has scanned through all the cells in the For statement do I want it to continue on to copying, assuming it has not found the value.

    So the code needs to work like this - I just can't figure out how to do that....

  4. #4
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Check existing data before copying in new data to avoid duplication

    try this

    I start by creating a boolean that is set to false.
    so this loops through your SO's....if you find it, you set the boolean to TRUE and you exit the FOR loop because found it....after that loop you look to see if the boolean is NOT set to true and then copy the data....again without data is test against this is untested....

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    08-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    132

    Re: Check existing data before copying in new data to avoid duplication

    Hah - this is very similar to what I just came up with while working through the logic of getting this to function properly.

    Is
    Please Login or Register  to view this content.
    the same as me saying
    Please Login or Register  to view this content.
    ?

  6. #6
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Check existing data before copying in new data to avoid duplication

    yes - they are logically equivalent....

  7. #7
    Forum Contributor
    Join Date
    08-16-2010
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    132

    Re: Check existing data before copying in new data to avoid duplication

    Beautiful! This worked - I just had to change around a few more things and it works like a charm. Thank you so much!

  8. #8
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Check existing data before copying in new data to avoid duplication

    Glad I could help and thanks for the "*"

+ 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. how to avoid copying the data that are formatted
    By kwfine in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-08-2013, 04:05 PM
  2. Copying existing comments and data in a list using data validation.
    By labexcel in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-03-2012, 05:41 AM
  3. How do I avoid copying data into blank cells
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-08-2006, 01:40 PM
  4. [SOLVED] How do I avoid copying data from hidden rows/columns?
    By Fred in forum Excel General
    Replies: 1
    Last Post: 03-31-2006, 06:10 PM
  5. data duplication check ?
    By Anthony in forum Excel General
    Replies: 4
    Last Post: 07-01-2005, 05:05 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