0

So I have this Workbook with 3 sheets, I collect some data from "Plan1" and output the filtered content to "Plan2". Them I´ve built the following code to search and match the sorted output with "Plan3" and select the matching items.

Problem is, it is only selecting 1 value on "Plan3" instead of all the matching ones. can someone point me in the right direction?

Below is the code I´ve written - and YES I´m new to vba and my code is really basic.

    Sub Compara()
Dim cell As Range
Dim temp As Range
For Each cell In Sheets("Plan2").Columns("C").Cells
    If cell <> "" And cell.Row <> 1 Then
        Set temp = Sheets("Conciliacao").Columns("C").Find(What:=cell.Value, _
        LookIn:=xlFormulas, _
        LookAt:=xlPart, _
        SearchOrder:=xlByRows, _
        SearchDirection:=xlNext)
        If Not temp Is Nothing Then
            ThisWorkbook.Sheets("Conciliacao").Select
            temp.EntireRow.Select

        End If
    End If
Next
End Sub

Thanks in advance,

Alex
  • 487
  • 1
  • 5
  • 10
  • You need another loop for the FindNext to retrieve all matches. – QHarr Jul 31 '18 at 14:40
  • Possible duplicate of [Find all matches in workbook using Excel VBA](https://stackoverflow.com/questions/19504858/find-all-matches-in-workbook-using-excel-vba) – QHarr Jul 31 '18 at 14:41
  • Why are you selecting cells? You should always [avoid using `.Select`/`.Activate`](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba) – BruceWayne Jul 31 '18 at 14:44
  • @BruceWayne, - Read about this but what is recommended? – Alex Jul 31 '18 at 15:08
  • @QHarr I saw that but I just want the results to be selected not replaced or moved, I tried changing the code but without much success. – Alex Jul 31 '18 at 15:10
  • What's the purpose of selecting the cells? What do you plan on doing after you have them selected? – BruceWayne Jul 31 '18 at 15:18
  • @BruceWayne - Sorry for not responding earlier. See After selecting them on Plan3 as stated It should get the selected values, locate on Plan1 and delete them. – Alex Jun 17 '19 at 15:18

0 Answers0