Página 1 de 1

Loop

Enviado: 24 Jan 2020 às 16:00
por GermaHeidel
Olá pessoal! Estou precisando de uma ajuda para uma planilha que uso aqui na empresa. Esse codigo roda normal, só que me surgiu outra variavel, preciso de mais 3 variaveis. Exemplo: Quando eu digitar no lugar de ok, 1 vai para planilha PCP 1, Quando eu digitar 2, vai para planilha PCP 2, quando digitar 3 vai para planilha PCP 3 e assim por diante, tentei copiar e colar o codigo adicionando as outras variaveis, mas não deu certo, imagino que tenha que criar um loop, mas não consegui. Por favor poderiam me ajudar. Segue o codigo que uso atualmente:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column <> 9 Then Exit Sub
If Target.Value <> "ok" Then Exit Sub
Dim LR As Long
With Sheets("PCP")
LR = .Cells(Rows.Count, 1).End(xlUp).Row
.Cells(LR + 1, 1).Resize(, 8).Value = Cells(Target.Row, 1).Resize(, 8).Value
End With
'Rows(Target.Row).Delete
End Sub

Re: Loop

Enviado: 24 Jan 2020 às 18:09
por osvaldomp
Segue uma sugestão.
Código: Selecionar todos
Private Sub Worksheet_Change(ByVal Target As Range)
 Dim LR As Long
  If Target.Column <> 9 Then Exit Sub
   With Sheets("PCP " & Target.Value)
   LR = .Cells(Rows.Count, 1).End(xlUp).Row
   .Cells(LR + 1, 1).Resize(, 8).Value = Cells(Target.Row, 1).Resize(, 8).Value
   End With
   'Rows(Target.Row).Delete
End Sub
obs. renomeie a planilha PCP como PCP 0 e em lugar de ok digite 0