Activate found cell

0

I'm having trouble activating the cell that was found.

The code is as follows:

Private Sub cmdPesquisar_Click()

    'Verificar se foi digitado um nome na primeira caixa de texto

    If Txtnif.Text = "" Then

        MsgBox "Digite o NIF de um cliente"

        Txtnif.SetFocus

        GoTo Linha1

    End If

    With Worksheets("Central.de.Clientes").Range("F:F")

        Set c = .Find(Txtnif.Value, LookIn:=xlValues, LookAt:=xlPart)

        If Not c Is Nothing Then

            c.Activate

            Txtnif.Value = c.Value

            Txtempresa.Value = c.Offset(0, -1).Value

            Txttelefone.Value = c.Offset(0, 1).Value

            Txtmorada.Value = c.Offset(0, 2).Value

            Txtlocal.Value = c.Offset(0, 3).Value

            Txtcontacto.Value = c.Offset(0, 4).Value

            Txtemailrel.Value = c.Offset(0, 5).Value

            Txtemailfact.Value = c.Offset(0, 6).Value

            'Carregando o botão de opção

            If c.Offset(0, 8) = "Masculino" Then

                OptionButton1.Value = True

            Else

                OptionButton2.Value = True

            End If

        Else

            MsgBox "Cliente não encontrado!"

        End If

    End With

    Linha1:

End Sub

But when I run, the following error appears:

And the debug identifies the line:

c.Activate

Can you help me identify the error in the code?

    
asked by anonymous 06.12.2017 / 17:42

1 answer

0

I believe you are trying to activate a cell in a worksheet that is hidden or is not active.

Try to activate the worksheet:

'[...]

' Ativar a Planilha:    
Worksheets("Central.de.Clientes").Activate

With Worksheets("Central.de.Clientes").Range("F:F")

    Set c = .Find(Txtnif.Value, LookIn:=xlValues, LookAt:=xlPart)

    If Not c Is Nothing Then

        c.Activate
' [...]
    
06.12.2017 / 20:09