+ Reply to Thread
Results 1 to 2 of 2

Replace data in secondary workbook if duplicate found

  1. #1
    Registered User
    Join Date
    06-17-2013
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    23

    Replace data in secondary workbook if duplicate found

    I have a workbook that has the user transfer their data to a second workbook every hour. Each record is a row of around 20 data points; in the last column I have code for the record, something like 42314-01 through 42304-24, where the suffix is each hour of the day, the first five digits are the numerations of the date. Each time the user submits their data, the code checks to make sure the record isn't already recorded in the second workbook, to prevent duplication.

    Right now, if the code detects a duplicate, the user can choose to not transfer it, or they may choose to transfer it anyway; there may have been an error in the initial transaction. What I want to do is overwrite the data if there is a duplicate, but I'm not sure how to do this.

    This is the code I'm using to detect the duplication:

    PHP Code: 
    Dim R As RangeAs Range 'CHECK DUPLICATION - R is the value to look for from this workbook, S is the range to look in target workbook

    Set R = Range("S" & ActiveCell.row)
    Set S = WkShtData.Columns("S").Find(R.Value, LookIn:=xlValues, LookAt:=xlWhole)

    Set Wkbk = Workbooks.Open(location & fileName, , , , , 1234) '
    Location name of target workbookdefined in GlobalVar
    Set WkShtData 
    Wkbk.Sheets("A1"'Name of worksheet in target workbook to use

    If Not S Is Nothing Then
        If MsgBox("This hour appears to have been already recorded. Continue with data transfer anyway?", vbYesNo, "User Input") = vbNo Then
            '
    Save data workbook and close
            errorType 
    "Duplicate value detected - User did not continue"
            
    Call WriteErrors(errorType'keeps track of errors that occur
            Wkbk.Save
            Wkbk.Close
            Exit Sub
        Else
            errorType = "Duplicate value detected - User Continued with transfer"
            Call WriteData '
    Sub that transfers data from this Workbook to data collection Workbook
        End 
    If
    Else
    End If 
    The WriteData sub looks for the first unused row in the target worksheet, and writes the data there, but I'm not sure how to replace a record. I use something like this to find the first unused row:

    PHP Code: 
    nextrow Sheet4.Cells(Sheet1.Rows.count"A").End(xlUp).row 
    So now, I need to take a row that has been found to already have the code I'm using to search with, and replace it with the new record. Any ideas on how to do this? I have 20 worksheets that use similar code, each with different data points. We're trying to not have to manually clean up the data every day. Thanks in advance.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Replace data in secondary workbook if duplicate found

    Maybe:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

+ 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. Replies: 1
    Last Post: 09-22-2015, 02:47 AM
  2. [SOLVED] macro to check for duplicates and copy data if no duplicate found
    By lwayl in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-22-2015, 01:31 AM
  3. Message box if duplicate found and clear the data from corresponding cells
    By sahal in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-01-2015, 06:00 AM
  4. Replies: 1
    Last Post: 12-11-2013, 09:09 PM
  5. Replies: 3
    Last Post: 07-24-2012, 12:54 AM
  6. loop through data twice & remove row if duplicate values are found
    By smokebreak in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-22-2010, 02:29 PM
  7. Append data if a duplicate found
    By HUBBUB88 in forum Excel General
    Replies: 0
    Last Post: 10-10-2005, 02:57 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