У меня есть электронная таблица, где у меня есть несколько дубликатов ID. Мне нужно извлечь конкретные дубликаты на основе строки в столбце рядом с идентификатором, используя код VBA. Например:
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
Заранее спасибо за помощь!