我有一个电子表格,如果我有多个ID重复项。我需要使用vba代码根据ID旁边的列中的字符串提取特定的重复项。例如:
Letter: t f t t t f f f
ID: 1 1 2 3 3 3 4 4
我需要提取具有字母t的数字3,字母t的数字1和两个f都具有数字4的重复项。
我创建了下面的代码,但仅提取了其中的1个重复代码。
Sub transfer_dups()
Sheets("OP").Activate
Dim OP As Worksheet
Dim Final As Worksheet
Dim lr As Integer 'lr = last row. Wanted to make it different from other parts of the code so there is not complications
Dim i As Integer 'This is working as my row counter for the forloop
'The code below will ensure that the data that was preciously populating the final filter sheet is cleared for a new process
Sheets("Final").Select
Range("A1:AQ300").ClearContents
'Searching and selecting in the OP sheet (Opportunities)
Sheets("OP").Select
lr = Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lr
'if CELL B2=B3 and cell A2<>A3 then
If Cells(i, 8) = Cells(i + 1, 8) And Cells(i, 7) <> Cells(i + 1, 7) Then
Range(Cells(i, 1), Cells(i, 48)).Copy 'This range may change if more columns are added
Sheets("Final").Select
Range("A300").End(xlUp).Offset(1, 0).PasteSpecial xlPasteFormulasAndNumberFormats 'Find the next available row
Sheets("OP").Select
预先感谢您的帮助!