Vídeo recomendado
https://youtu.be/diWPPPhW-9E

Ajuda com código VBA

Fórum para dúvidas sobre os fundamentos da linguagem de programação Visual Basic no contexto do VBA
Germa
Acabou de chegar
Acabou de chegar
Mensagens: 2
Registrado em: Sex Jan 24, 2020 4:10 pm

Ajuda com código VBA

Mensagem por Germa »

Boa tarde pessoal!
Poderiam me ajudar com esse código, o que esta errado? Ele funciona, mas quando executo dá erro e quando vou em depurar joga para a linha "If Target.Column <> 6 Then Exit Sub"

Código: Selecionar todos

Private Sub Worksheet_Change(ByVal Target As Range)

    'C01
    If Target.Column <> 6 Then Exit Sub
    If Target.Value = 1 Then
        Dim LR1 As Long
        With Sheets("C01")
            LR = .Cells(Rows.Count, 1).End(xlUp).Row
            .Cells(LR + 1, 1).Resize(, 5).Value = Cells(Target.Row, 1).Resize(, 5).Value
        End With
        Rows(Target.Row).Delete


        'C02
        If Target.Column <> 6 Then Exit Sub
        If Target.Value = 2 Then
            Dim LR2 As Long
            With Sheets("C02")
                LR2 = .Cells(Rows.Count, 1).End(xlUp).Row
                .Cells(LR2 + 1, 1).Resize(, 5).Value = Cells(Target.Row, 1).Resize(, 5).Value
            End With
            Rows(Target.Row).Delete


            'C03
            If Target.Column <> 6 Then Exit Sub
            If Target.Value = 3 Then
                Dim LR3 As Long
                With Sheets("C03")
                    LR3 = .Cells(Rows.Count, 1).End(xlUp).Row
                    .Cells(LR3 + 1, 1).Resize(, 5).Value = Cells(Target.Row, 1).Resize(, 5).Value
                End With
                Rows(Target.Row).Delete


                'C04
                If Target.Column <> 6 Then Exit Sub
                If Target.Value = 4 Then
                    Dim LR4 As Long
                    With Sheets("C04")
                        LR4 = .Cells(Rows.Count, 1).End(xlUp).Row
                        .Cells(LR4 + 1, 1).Resize(, 5).Value = Cells(Target.Row, 1).Resize(, 5).Value
                    End With
                    Rows(Target.Row).Delete

                End If
            End If
        End If
    End If


End Sub


Disable adblock

This site is supported by ads and donations.
If you see this text you are blocking our ads.
Please consider a Donation to support the site.


Wagner Morel
Manda bem
Manda bem
Mensagens: 107
Registrado em: Qua Nov 29, 2017 11:51 am
Localização: Fortaleza - CE

Re: Ajuda com código VBA

Mensagem por Wagner Morel »

Germa,

Bom dia!

Sugiro anexar o arquivo aqui para que possamos rodar, depurar e saber se ocorre o erro, bem como que erro é esse.


Germa
Acabou de chegar
Acabou de chegar
Mensagens: 2
Registrado em: Sex Jan 24, 2020 4:10 pm

Re: Ajuda com código VBA

Mensagem por Germa »

Wagner, bom dia!
Agradeço pela intenção em ajudar. Consegui resolver o problema aqui utilizando um outro codigo. Mas de qualquer forma obrigado.


Disable adblock

This site is supported by ads and donations.
If you see this text you are blocking our ads.
Please consider a Donation to support the site.


Responder