Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
  • Avatar do usuário
Avatar do usuário
Por Pessoa
Posts Avatar
#47587
Pessoal, precisava que um código onde cada condição ocorresse uma macro seja acionada. Quando determinada celula seja preenchida com um valor colado chama uma macro. Tentei com codigo abaixo mas só realizar a primeira macro. Quando as proximas celulas são preenchidas as demais macros nao sao acionadas

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$L$8960" Then
Call ImportaCadastro2
If Target.Address = "$L$17960" Then
Call ImportaCadastro3
If Target.Address = "$L$26960" Then
Call ImportaCadastro4
If Target.Address = "$L$35960" Then
Call ImportaCadastro5
If Target.Address = "$L$44960" Then
Call ImportaCadastro6
If Target.Address = "$L$53960" Then
Call ImportaCadastro7
If Target.Address = "$L$62960" Then
Call ImportaCadastro8

End If

End Sub
Por Falcao98
#47593
Boa Tarde!
Amigo, em vez de usar vários IFs, tenta usar ElseIf. Vai resolver seu caso. Seu código, vai ficar da seguinte forma:

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$L$8960" Then
Call ImportaCadastro2
ElseIf Target.Address = "$L$17960" Then
Call ImportaCadastro3
ElseIf Target.Address = "$L$26960" Then
Call ImportaCadastro4
ElseIf Target.Address = "$L$35960" Then
Call ImportaCadastro5
ElseIf Target.Address = "$L$44960" Then
Call ImportaCadastro6
ElseIf Target.Address = "$L$53960" Then
Call ImportaCadastro7
ElseIf Target.Address = "$L$62960" Then
Call ImportaCadastro8

End If

End Sub

Espero ter ajudado!
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord