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
#65119
Pessoal

Tenho dados mensais em uma tabela dinâmica
Como faço para que, quando eu digitar "Mai" na célula J5,
ele execute a Macro que vai filtrar nesse mês a tabela dinâmica?


Se ajudar, eu achei em um site este código, mas não está funfando aqui:
====================
Private Sub Worksheet_Change(ByVal Target As Range)

'Como Executar A Macro Com Base No Valor Selecionado Da Lista Suspensa No Excel?
'FONTE: https://pt.extendoffice.com/documents/e ... -list.html

If Not Intersect(Target, Range("J6")) Is Nothing Then
Select Case Range("J6")
Case "Mai": Mai 'se Mai na célula J6, e ele roda a macro "Mai"
Case "Jun": Jun
Case "Jul": Jul
End Select
End If
End Sub
====================
MINHA MACRO QUE FILTRA A TAB DINAMICA PELO MÊS:
Sub Mai()

ActiveSheet.PivotTables("Tabela dinâmica10").PivotFields("MÊS").ClearAllFilters
ActiveSheet.PivotTables("Tabela dinâmica10").PivotFields("MÊS").CurrentPage = _
"5/2021"
ActiveSheet.PivotTables("Tabela dinâmica11").PivotFields("MÊS").ClearAllFilters
ActiveSheet.PivotTables("Tabela dinâmica11").PivotFields("MÊS").CurrentPage = _
"5/2021"

End Sub

Agradeço desde já qualquer ajuda, obrigado. ;)

Imagem
#65123
Código: Selecionar todos
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Texto As String
    Dim arr As Variant
    
    arr = Array("Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez")
      If Not Intersect(Target, Me.Range("J5")) Is Nothing Then
            Texto = Application.WorksheetFunction.Match(Range("J5").Value2, arr, 0)
            Me.PivotTables("Tabela dinâmica10").PivotFields("MÊS").ClearAllFilters
            Me.PivotTables("Tabela dinâmica10").PivotFields("MÊS").CurrentPage = Texto & "/2021"
      End If
End Sub
JacoStein agradeceu por isso
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