+ Reply to Thread
Results 1 to 5 of 5

Match the duplicates and copy only selected column data

Hybrid View

  1. #1
    Registered User
    Join Date
    01-29-2012
    Location
    India
    MS-Off Ver
    Excel 2013
    Posts
    18

    Cool Match the duplicates and copy only selected column data

    Hi there,

    I have found many scripts that copy the data from one to another but I need help with my files.
    I have provided complete description in the Excel file itself.

    However I am writing it here for reference:
    I have 2 Excel files: 1 is "MasterMaster File with over 2 lakh of data_sample"
    2 is "Update Data from master"

    Both the files have same type of columns but file 2 does not have some columns same as master file.I want to update the second file and get the data from Master.

    Master File with over 2 lakh of data_sample.xlsx
    Update Data from master.xlsx

    Thanks,
    Yogi

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Match the duplicates and copy only selected column data

    use this macro on Update Data from master, the 2 wb must be in the same directory, master wb not open
    Public Sub m()
        Dim wk1 As Workbook, wk2 As Workbook, sh1 As Worksheet, sh2 As Worksheet
        Dim rng2 As Range, rfound As Range
        Dim LR As Long
        
        
        Set wk1 = ThisWorkbook
        Set wk2 = Workbooks.Open(ThisWorkbook.Path & "\Master File with over 2 lakh of data_sample.xlsx")
        Set sh1 = wk1.Worksheets("Sheet1")
        Set sh2 = wk2.Worksheets("Sheet1")
        Set rng2 = sh2.UsedRange
        
        Application.ScreenUpdating = False
        LR = sh1.Range("A" & Rows.Count).End(xlUp).Row
    '    Stop
        With sh1
            For j = 2 To LR
                regID = .Cells(j, 1).Value
                Set rfound = rng2.Find(What:=regID, After:=ActiveCell, LookIn:=xlFormulas _
                    , LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                    MatchCase:=False, SearchFormat:=False)
                If Not rfound Is Nothing Then
                  frow = rfound.Row
                  .Cells(j, 3).Value = sh2.Cells(frow, 3).Value
                  .Cells(j, 4).Value = sh2.Cells(frow, 5).Value
                  .Cells(j, 5).Value = sh2.Cells(frow, 6).Value
                  .Cells(j, 6).Value = sh2.Cells(frow, 8).Value
                  .Cells(j, 7).Value = sh2.Cells(frow, 9).Value
                  .Cells(j, 8).Value = sh2.Cells(frow, 10).Value
                End If
            Next
        End With
        
       
        wk2.Close
       
    End Sub
    If solved remember to mark Thread as solved

  3. #3
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Match the duplicates and copy only selected column data

    hi Yogi28, different VB approach, please check attachment, save both files to the same folder, open Update_Data_from_master(1).xlsm and press "Update" button

  4. #4
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Match the duplicates and copy only selected column data

    watersev I think is better
    If mainwb Is Nothing Then Set mainwb = Workbooks.Open(ThisWorkbook.Path & "\Master File with over 2 lakh of data_sample.xlsx")

  5. #5
    Registered User
    Join Date
    01-29-2012
    Location
    India
    MS-Off Ver
    Excel 2013
    Posts
    18

    Unhappy Re: Match the duplicates and copy only selected column data

    Downloaded the 2 new files. When I click the update button it gives runtime error. I think file name changed due to some missing font. Is that the case?
    Attached Images Attached Images

+ 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