+ Reply to Thread
Results 1 to 3 of 3

Copy & Paste Unique Values

Hybrid View

  1. #1
    Registered User
    Join Date
    10-27-2011
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2007
    Posts
    3

    Question Copy & Paste Unique Values

    I have several Excel files that are in the same format, but with unique data. I would like to upload the data to a central file once a month. I have created the below macro in each of the files to append the data to the central "master" file. It works well, but I would like to add code so that it will not duplicate data, but replace it with the latest values if the file had already been submitted. In the individual files, each row of data has a unique value in column A. It would be ideal if the macro would replace the line item in the central "master" file if the unique value was already present. Does anyone have any ideas on how to modify my macro code to do this?
    Sub Master_DSC_Upload()
    
    ' Master_DSC_Upload Macro
    ' Uploads Input data from each month's file into the DSC Master File. *Note that the location of the DSC Master File is located in cell L8 of the "Intro" tab.
    
    Dim wbk As Workbook
    Dim lRow As Long
    Dim jRow As Long
    Dim iCol As Integer
    Dim ws As Worksheet
    
     
     strSecondFile = Sheets("Intro").Range("L8").Value
    
    ThisWorkbook.Sheets("Input").Select
    Range("A2:AY466").Select
    Selection.Copy
    
    
    Set wbk = Workbooks.Open(strSecondFile)
    wbk.Sheets("Master_Input").Select
    
        iRow = 0
        For iCol = 1 To 256
            jRow = Cells(Rows.Count, iCol).End(xlUp).Row
            If Cells(jRow, iCol).Value = "" Then
                jRow = 0
            End If
            If jRow > iRow Then
                iRow = jRow
            End If
        Next iCol
        Range("A" & iRow + 1).Select
        
        Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=False
              
        Windows("Daily Schedule Control Master File.xlsm").Close SaveChanges:=True
     
    ThisWorkbook.Activate
    
    End Sub
    Last edited by Leith Ross; 04-04-2012 at 04:50 PM. Reason: Added Code Tags

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Re: Copy & Paste Unique Values

    Under the data ribbon, there is an icon Called "Remove Duplicates"
    Experiment with it.
    You could use it after all the data has been transferred to the sheet.
    Once you have it figured out, use your macro recorder to get the code.

  3. #3
    Registered User
    Join Date
    10-27-2011
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Copy & Paste Unique Values

    Thanks! I will give that a try.

    Quote Originally Posted by davesexcel View Post
    Under the data ribbon, there is an icon Called "Remove Duplicates"
    Experiment with it.
    You could use it after all the data has been transferred to the sheet.
    Once you have it figured out, use your macro recorder to get the code.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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