+ Reply to Thread
Results 1 to 8 of 8

Stop Macro bringing across duplicate data

  1. #1
    Registered User
    Join Date
    10-31-2017
    Location
    Liverpool, England
    MS-Off Ver
    2013
    Posts
    5

    Stop Macro bringing across duplicate data

    Hi all,

    I've found some help on here in the past, so thought I would try my luck again.

    I currently have a Workbook that is pulling data from one sheet to another based on the value of a specific row. I need it to read the value "Yes" in one of the columns and copy the entire row to the new sheet. I have acheived this, created a button to run the Macros and copy the data over. All seems fine, however if you click the button again, it brings the data over again.

    I need something that will enable the Macros to check if the value in Column B is already present, then it will not copy across. Please see the current code below:

    Please Login or Register  to view this content.
    Just to reiterate that the above works for the initial purpose of what I wanted, I just need it so that every time the button is clicked to update the new tab (we will need to do this each day) it checks if the data is already present.

    If an example work book is required I can try and sort this out, but the nature of my work is quite sensitive so ideally I would not do this.

    Hoping somebody is able to help! Thanks
    Last edited by excel_learner2; 02-08-2018 at 12:51 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,377

    Re: Stop Macro bringing across duplicate data

    If an example work book is required I can try and sort this out, but the nature of my work is quite sensitive so ideally I would not do this.
    Yep, do that. It's not easy to work out a solution without being able to test it. I don't understand why, for example, you do this:
    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,176

    Re: Stop Macro bringing across duplicate data

    import the data to a 'temp' sheet.
    run REMOVE DUPLICATES,
    then copy that set to the final sheet.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,377

    Re: Stop Macro bringing across duplicate data

    I should also have said, Welcome to the forum BUT ...

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

  5. #5
    Registered User
    Join Date
    10-31-2017
    Location
    Liverpool, England
    MS-Off Ver
    2013
    Posts
    5

    Re: Stop Macro bringing across duplicate data

    Thanks TMS, I have used the code tag around the code now.

    I will have to do it in the morning, but I will upload a sheet with some temporary data in tomorrow morning so things are a bit easier to explain.

    Thanks again

  6. #6
    Registered User
    Join Date
    10-31-2017
    Location
    Liverpool, England
    MS-Off Ver
    2013
    Posts
    5

    Re: Stop Macro bringing across duplicate data

    Hi,

    I have a sample document that I have removed the majority of information from, I have left a few sample records on the sheet but removed company names and contact details.

    In column C, "Ref. document number", this is what will be needed to be used to identify whether the data is already on the spreadsheet or not.

    The workbook has been built up over time using various bits and pieces of code, so some of this may look messy. I know there will be risks of this corrupting the longer we use/more data is compiled to the book, however this is only a temporary measure so not a real long term concern. There will be similar code to what I need elsewhere in the spreadsheet but I am struggling to get my head around how to apply this to what I need below.

    Just a summary of the assistance I require:

    I want the sheet to copy a record to the "Uncollectables" tab when the word "Yes" is in the column "Uncollectable?" (R). The intention is to update this column throughout the day, and once the days work is completed, click the button top left which will run the code and copy the appropriate records to the next tab. The current problem is that whenever I press that button, it will copy all records regardless is they are already in the "Uncollectables" tab.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,377

    Re: Stop Macro bringing across duplicate data

    Well, I guess you can check whether or not the ID has already been copied across, but that would require you to loop through all the records, check them individually (I'd use COUNTIF). Alternatively, you could add a column, say headed "posted", and add a flag to all the records when they are posted. Then you would filter for unposted records; if there are any, copy them.

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,517

    Re: Stop Macro bringing across duplicate data

    excel_learner2,

    Why not change "Yes" to something like "Done" after you copy the row?

    BTW, AutoFilter would suite in this situation.

+ 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] Macro check as bringing wrong line through
    By aaaaaaiden in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-12-2014, 06:11 AM
  2. [SOLVED] Stop Vlookup bringing back 0's or #REF! and bring back blanks instead
    By Carling73 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-30-2013, 04:43 PM
  3. Stop macro at the end of data / make macro faster
    By Shaner73 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 08-17-2010, 08:14 AM
  4. bringing up the data -> form... box via macro
    By mdkruse2 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-30-2008, 04:01 PM
  5. bringing up the data -> form... box via macro
    By splodgecat in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-17-2007, 06:52 PM
  6. Stop Macro if there is no data
    By STEVEB in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 02-08-2006, 05:45 PM
  7. [SOLVED] Bringing up the Unhide Sheet list via macro
    By PCLIVE in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-22-2005, 02:45 PM
  8. How do you Stop Entering Duplicate Data in a Column?
    By Satraj in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 11-04-2005, 09:10 AM

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