+ Reply to Thread
Results 1 to 7 of 7

Pasting new row in table, only if row doesn't already exist

  1. #1
    Registered User
    Join Date
    03-16-2016
    Location
    indiana, US
    MS-Off Ver
    2016
    Posts
    33

    Pasting new row in table, only if row doesn't already exist

    Hello everyone,
    I am working on a project where I am pasting rows of information into a table. I have a button that copies a row from one place and pastes it into the first empty row in a table. I want to prevent it from pasting the row if the exact same row already exists in the table. What is the best way to do this?

    Here is the code to paste the row upon the button click:

    Private Sub SaveButton_Click()

    Sheets("Sheet1").Range("A2:BI2").Copy
    Sheets("Database").Range("A60000").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteFormats
    Sheets("Database").Range("A60000").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False

    End Sub

    Thank you for your help.

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Pasting new row in table, only if row doesn't already exist

    Quote Originally Posted by shoulddt View Post
    Hello everyone,
    I am working on a project where I am pasting rows of information into a table. I have a button that copies a row from one place and pastes it into the first empty row in a table. I want to prevent it from pasting the row if the exact same row already exists in the table. What is the best way to do this?

    Here is the code to paste the row upon the button click:

    Private Sub SaveButton_Click()

    Sheets("Sheet1").Range("A2:BI2").Copy
    Sheets("Database").Range("A60000").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteFormats
    Sheets("Database").Range("A60000").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False

    End Sub

    Thank you for your help.
    Disregard this reply.
    Last edited by JLGWhiz; 03-16-2016 at 03:57 PM.

  3. #3
    Forum Contributor kalbasiatka's Avatar
    Join Date
    02-27-2016
    Location
    Brest, Belarus
    MS-Off Ver
    2021
    Posts
    224

    Re: Pasting new row in table, only if row doesn't already exist

    maybe this will help
    Please Login or Register  to view this content.
    Last edited by kalbasiatka; 03-16-2016 at 04:23 PM.
    To do it for me and help me it is 2 different things!
    Sorry for my english, blame Google translator

  4. #4
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Pasting new row in table, only if row doesn't already exist

    See if this will work for your button code.
    Please Login or Register  to view this content.
    It will not be fast if you have a large database.

  5. #5
    Registered User
    Join Date
    03-16-2016
    Location
    indiana, US
    MS-Off Ver
    2016
    Posts
    33

    Re: Pasting new row in table, only if row doesn't already exist

    That worked great JLGWhiz. Thank you.

  6. #6
    Registered User
    Join Date
    02-07-2016
    Location
    Canada
    MS-Off Ver
    13
    Posts
    65

    Re: Pasting new row in table, only if row doesn't already exist

    Will it check many rows?
    I mean if I have 25 rows with data in Sheet1, can VBA compare each row and copy in Database unique rows only?

  7. #7
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Pasting new row in table, only if row doesn't already exist

    Quote Originally Posted by R12345 View Post
    Will it check many rows?
    I mean if I have 25 rows with data in Sheet1, can VBA compare each row and copy in Database unique rows only?
    The code provided is based on what you are currently doing with your button, which is copying a single row from one sheet to another. the code does check all rows on the destination sheet to determine if there is a duplicate. If you want to change your parameters, I suggest you start a new thread and provide the details of what you want to do.

    Regards. JLG

+ 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] If Item on Sheet Doesn't Exist in Specified Table, Add It To Table
    By EnigmaMatter in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-21-2014, 12:39 PM
  2. [SOLVED] Macro Pivot Table: Most elegant way to skip a "do not display" if element doesn't exist
    By Skotzmun in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-22-2013, 05:03 AM
  3. Replies: 0
    Last Post: 03-10-2013, 04:19 PM
  4. If a Value Doesn't Exist in a Table, Return ""
    By Ocean Zhang in forum Excel General
    Replies: 7
    Last Post: 06-23-2011, 04:13 PM
  5. how to stop VBA overwriting Pivot Table Value if Value doesn't exist
    By karl1985 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-27-2010, 06:47 AM
  6. Does a tab exist or doesn't it?
    By rjwebgraphix in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-28-2007, 08:57 AM
  7. Replies: 4
    Last Post: 06-18-2006, 01:10 PM

Tags for this Thread

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