Consulta em tabela ...
 
Notifications
Clear all

Consulta em tabela dinâmica

4 Posts
2 Usuários
0 Reactions
1,056 Visualizações
(@rickeera)
Posts: 2
New Member
Topic starter
 

Boa tarde Galera, meu caso é o seguinte:

Tenho algumas dinâmicas que estão sendo alimentadas do banco de dados mês a mês, ou seja, 2014 eu tenho de janeiro a abril, porém criei alguns checkbox para que o usuário tenha acesso as informações filtrando mês a mês, porém, quando ele selecionar algum mês que ainda não existe, por exemplo, maio, a planilha dá um erro e não consigo tratar isso.
Minha ideia seria alguma espécie de condição, se o mês q o cara selecionou não existir, então já aparece uma mensagem para o cara informando isso...
segue meu código para o mes de maio e a função...

CODIGO:

Private Sub CheckBox5_Click()
'Mai
If CheckBox5.Value = True Then
'Plan1.Unprotect ("AAA")
Plan1.Range("F5").Value = Plan9.Range("B7").Value
Plan1.Range("F4").Value = 21 'atualizar abril
'Plan1.Protect ("AAA")

If CheckForPivotValue(Plan11.PivotTables("Tabela dinâmica2"), "MES", "Mai") Then
With Plan11.PivotTables("Tabela dinâmica2").PivotFields("MES")
.PivotItems("Mai").Visible = True
End With
Else
MsgBox "Mês vazio"
End If

If CheckForPivotValue(Plan11.PivotTables("Tabela dinâmica3"), "MES", "Mai") Then
With Plan13.PivotTables("Tabela dinâmica3").PivotFields("MES")
.PivotItems("Mai").Visible = True
End With
Else
MsgBox "Mês Vazio 2"
End If

If CheckForPivotValue(Plan11.PivotTables("Tabela dinâmica1"), "MES", "Mai") Then
With Plan14.PivotTables("Tabela dinâmica1").PivotFields("MES")
.PivotItems("Mai").Visible = True
End With
Else
MsgBox "Mês Vazio 3"
End If

End If

If CheckBox5.Value = False Then
'Plan1.Unprotect ("AAA")
Plan1.Range("F5").Value = 0
Plan1.Range("F4").Value = 0
'Plan1.Protect ("AAA")
CheckBox1.Value = True

'With Plan11.PivotTables("Tabela dinâmica2").PivotFields("MES")
' .PivotItems("Mai").Visible = False
'End With
'With Plan13.PivotTables("Tabela dinâmica3").PivotFields("MES")
' .PivotItems("Mai").Visible = False
'End With
'With Plan14.PivotTables("Tabela dinâmica1").PivotFields("MES")
' .PivotItems("Mai").Visible = False
'End With
End If
End Sub

A FUNÇÃO usada para esse cara:

Function CheckForPivotValue(pvtPivotName As Object, strFieldName As String, strCheckValue As String) As Boolean
'''''''' pivot table must be on active sheet
Dim i As Integer

With pvtPivotName
For i = 1 To .PivotFields(strFieldName).PivotItems.Count
If strCheckValue = .PivotFields(strFieldName).PivotItems(i).Name Then
' value is found!
CheckForPivotValue = True
Exit Function
End If
Next i
End With
'value was not found
CheckForPivotValue = False
End Function

Help me please!!! :? :?

 
Postado : 29/04/2014 2:36 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
(@rickeera)
Posts: 2
New Member
Topic starter
 

Enviei a planilha anexo, mas não sei se subiu...

 
Postado : 30/04/2014 8:07 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa tarde!!

Ainda não tem anexo!

Att

 
Postado : 30/04/2014 1:50 pm