Selecionando célula quando os valores correspondem

0

O código abaixo encontra o valor que eu introduzo em "K2" na planilha 1 e depois procura o mesmo valor na planilha 2. Eu gostaria que, quando encontrasse uma correspondência, selecionasse aquela célula específica. Alguém pode me ajudar com isso?

Sub Macro()
    Dim WS As Worksheet
    Dim rSearchRng As Range
    Dim EndNum As Long
    Dim vFindVar As Variant'

    Set WS = ActiveWorkbook.Worksheets("Sheet2")

    EndNum = WS.Range("A1").End(xlDown).Row

    Set rSearchRng = WS.Range("A1:A" & CStr(EndNum))
    Set vFindVar = rSearchRng.Find(Range("K2").Value)
    If Not vFindVar Is Nothing Then
        MsgBox "Match"
    Else
        MsgBox "No Match Found"
    End If
End Sub
    
por Eric 13.12.2017 / 23:33

1 resposta

1
Sub Macro()
Dim WS As Worksheet
Dim rSearchRng As Range
Dim EndNum As Long
Dim vFindVar As Variant'
Dim wsOrig as worksheet

Set wsOrig as activesheet
Set WS = ActiveWorkbook.Worksheets("Sheet2")

EndNum = WS.Range("A1").End(xlDown).Row

Set rSearchRng = WS.Range("A1:A" & CStr(EndNum))
Set vFindVar = rSearchRng.Find(wsOrig.Range("K2").Value)
If Not vFindVar Is Nothing Then
    'to select a cell the sheet must be active
    WS.Activate
    vFindVar.Select
Else
    MsgBox "No Match Found"
End If

End Sub
    
por 13.12.2017 / 23:41