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
#5892
Olá,

Estava precisando de algumas ajudas e criei um tópico (link abaixo), onde o Parkeless conseguiu resolver meu problema.
http://gurudoexcel.com/forum/viewtopic.php?f=7&t=1061

Como não conheço sobre VBA, ele também me explicou e consegui entender um pouco do que ele desenvolveu.

A planilha que estava (que ele mechou para mim) está assim:

Imagem
A coluna "EMPRESA", quando adiciona ou altera alguém, ele atualiza a tabela que está na aba "SITUAÇÃO FINANCEIRA"
Imagem
Em ambos os casos, as colunas "EMPRESA" está na célula B2.

O código macro que ele me mandou foi esse:
Código: Selecionar todos
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range
On Error GoTo Erro
If Target.Column = 2 Then
    Application.ScreenUpdating = False
    If Target = "" Or Target.Row <> Sheets(2).Range("B1000000").End(xlUp).Row Then
        Sheets(2).ListObjects("Tabela5").Resize Range("$B$2:$N$" & Sheets(1).Range("B1000000").End(xlUp).Row & "")
    End If
    Cells(Target.Offset(1, 0).Row, 2).Select
        Application.ScreenUpdating = True

End If
Exit Sub


Erro:
MsgBox "Aviso: as fórmulas da aba " & Sheets(2).Name & " não puderam ser atualizada automaticamente!", vbExclamation

End Sub
Até ai está funcionando tudo direito! O problema começou quando fiz o seguinte:
Fui personalizar a planilha, colocando cabeçalho e etc.

Após adicionar cabeçalho, a tabela desceu algumas linhas, ficando agora em B7:

Imagem
Imagem

Após fazer isso, tentei editar o VBA em base ao que o Parkeless explicou, ficou assim:
Código: Selecionar todos
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range
On Error GoTo Erro
If Target.Column = 2 Then
    Application.ScreenUpdating = False
    If Target = "" Or Target.Row <> Sheets(3).Range("B1000000").End(xlUp).Row Then
        Sheets(3).ListObjects("TabelaSITUACAO").Resize Range("$B$7:$N$" & Sheets(1).Range("B1000000").End(xlUp).Row & "")
    End If
    If Target = "" Or Target.Row <> Sheets(4).Range("B1000000").End(xlUp).Row Then
        Sheets(4).ListObjects("TabelaJan").Resize Range("$B$7:$N$" & Sheets(1).Range("B1000000").End(xlUp).Row & "")
    End If
    Cells(Target.Offset(1, 0).Row, 7).Select
        Application.ScreenUpdating = True

End If
Exit Sub



Erro:
MsgBox "Aviso: as fórmulas da aba " & Sheets(3).Name & " não puderam ser atualizada automaticamente!", vbExclamation

End Sub
Não sei se se está certo, mas mesmo assim, se eu adicionar um novo cliente, ele não expande a tabela na outra tabela.

Se tiver alguma dúvida, vou encaminhar a tabela em anexo.

Abraços
Você não está autorizado a ver ou baixar esse anexo.
#5893
Olá novamente Rafa!

Tenta isso:
Código: Selecionar todos
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range
'On Error GoTo Erro
On Error GoTo 0
If Target.Column = 2 Then
    Application.ScreenUpdating = False
    If Target = "" Or Target.Row <> Sheets(3).Range("B1000000").End(xlUp).Row Then
        Sheets("SITUAÇÃO FINANCEIRA").ListObjects("TabelaSITUACAO").Resize Range("$B$7:$N$" & Sheets("CLIENTE").Range("B1000000").End(xlUp).Row & "")
    End If
    If Target = "" Or Target.Row <> Sheets(4).Range("B1000000").End(xlUp).Row Then
        Sheets("JAN").ListObjects("TabelaJan").Resize Range("$B$7:$N$" & Sheets("CLIENTE").Range("B1000000").End(xlUp).Row & "")
    End If
    Cells(Target.Offset(1, 0).Row, 7).Select
        Application.ScreenUpdating = True

End If
Exit Sub



Erro:
MsgBox "Aviso: as fórmulas da aba SITUAÇÃO FINANCEIRA não puderam ser atualizada automaticamente!", vbExclamation

End Sub
No código anterior, eu tinha referenciado as abas como números ( sheets(1) ); como você criou novas abas, essa ordem mudou, então o Excel estava se perdendo. Alterei o código indicando o nome das abas, ao invés do seu número.
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