I am trying to create a code that will search for duplicate values in the different sheets of a workbook, then cut, paste and sort the items in the nextworkbook. The data are account numbers and sorted in ascending order. The data is divided into different sheets equally. So it can happen that the last last account from sheet 1 is the same as the first account in sheet2. In this case, the code will cut the row of information from sheet1, move it to sheet2 and sort sheet2, so that the same process can be repeated for sheet2, sheet3 and so on. The codes that I have so far are as below. Can anyone help me with this? Thank you.
Sub Completed_Projects() Dim i, rw As Integer, counter, firstvalue, lastvalue As Integer
counter = 1
For i = 1 To Worksheets.Count - 1 Application.ScreenUpdating = False firstvalue = Sheets(i + 1).Range("a1").Value lastvalue = Sheets(i).Range("a1").End(xlDown).Value
For rw = 100 To 1 Step -1
If Sheets(i).Range("a" & rw) = firstvalue Then
Rows(rw).Copy
Sheets(i + 1).Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial _
Paste:=xlPasteValues
Rows(rw).EntireRow.Delete Shift:=xlUp
Sheets(i + 1).Range("a1").Sort key1:=Sheets(i + 1).Columns(1), order1:=xlAscending, Header:=xlNo
counter = counter + 1
End If
Next rw
Next i
Application.ScreenUpdating = True
End Sub
برچسب:
نویسنده: استخدام کار