JUNIOR TARGINO
10-11-2010 18:11:26
Tenho a planilha 22 com o código abaixo, e Quando eu digito algum nome na célula B2 o cód. faz uma busca na plan.23. O que eu quero é inserir outra célula. Quero fazer a busca por dois critérios. Ex.: célula B2 = "João" e célula B3 = "Limoeiro do Norte" aí a plan. faz a busca por esses dois critérios.
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
' Verifica se o valor alterado foi na célula E1
If Not Intersect([B2], Target) Is Nothing Then
Dim lastRow As Long
Dim lastResultRow As Long
Dim x As Long
' Verifica qual a ultima célula preenchida
lastRow = Plan22.Cells(Rows.Count, 1).End(xlUp).Row
' Apaga valores anteriores
Plan23.Range("A5:M65536").ClearContents
lastResultRow = 5
' Ciclo em todas as linhas
For x = 2 To lastRow '1 coluna pequisa
' verifica se o valor é igual ao da pesquisa
If UCase(Plan22.Cells(x, 1).Value) = UCase(Plan23.[B2].Value) Then
'Plan22.Cells(x, 2).Value = Plan23.[F2].Value Then '1 coluna pequisa
' Copia os valores
Plan23.Cells(lastResultRow, 2).Value = Plan22.Cells(x, 2).Value
Plan23.Cells(lastResultRow, 3).Value = Plan22.Cells(x, 4).Value
Plan23.Cells(lastResultRow, 4).Value = Plan22.Cells(x, 6).Value
Plan23.Cells(lastResultRow, 5).Value = Plan22.Cells(x, 8).Value
Plan23.Cells(lastResultRow, 6).Value = Plan22.Cells(x, 10).Value
Plan23.Cells(lastResultRow, 7).Value = Plan22.Cells(x, 12).Value
Plan23.Cells(lastResultRow, 8).Value = Plan22.Cells(x, 14).Value
Plan23.Cells(lastResultRow, 9).Value = Plan22.Cells(x, 16).Value
Plan23.Cells(lastResultRow, 10).Value = Plan22.Cells(x, 18).Value
Plan23.Cells(lastResultRow, 11).Value = Plan22.Cells(x, 20).Value
Plan23.Cells(lastResultRow, 12).Value = Plan22.Cells(x, 22).Value
Plan23.Cells(lastResultRow, 13).Value = Plan22.Cells(x, 24).Value
lastResultRow = lastResultRow + 1
End If
Next
'
End If
End Sub
Agradeço muito aos internautas do fórum Tomáz...