Filter a Pivot Table Based on Cell
up vote
0
down vote
favorite
I have used https://www.mrexcel.com/forum/excel-questions/950078-filtering-pivot-table-based-cell-value.html to create the code below but I am getting an error on
Set Field = pt.PivotFields("EmployeeName")
It is saying
Unable to get the PivotFields property of the PivotTable class
Even though EmployeeName
is a field in my pivot table. Now I do have 2 databases in the Data Model that both have EmployeeName
as a field and they are linked via a relationship. Do I need to specify which database I want to use and how would I do that? My script is below for reference.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'This line stops the worksheet updating on every change, it only updates when cell
'H6 or H7 is touched
If Intersect(Target, Range("H6:H7")) Is Nothing Then Exit Sub
'Set the Variables to be used
Dim pt As PivotTable
Dim Field As PivotField
Dim NewCat As String
'Here you amend to suit your data
Set pt = Worksheets("2018IndSales").PivotTables("PivotTable4")
Set Field = pt.PivotFields("EmployeeName")
NewCat = Worksheets("2018IndSales").Range("H6").Value
'This updates and refreshes the PIVOT table
With Worksheets("2018IndSales").PivotTables("PivotTable4").PivotFields("EmployeeName")
.ClearAllFilters
.PivotFilters.Add Type:=xlCaptionEquals, Value1:=Worksheets("2018IndSales").Range("H6").Value
End With
End Sub
excel vba excel-vba pivot-table
add a comment |
up vote
0
down vote
favorite
I have used https://www.mrexcel.com/forum/excel-questions/950078-filtering-pivot-table-based-cell-value.html to create the code below but I am getting an error on
Set Field = pt.PivotFields("EmployeeName")
It is saying
Unable to get the PivotFields property of the PivotTable class
Even though EmployeeName
is a field in my pivot table. Now I do have 2 databases in the Data Model that both have EmployeeName
as a field and they are linked via a relationship. Do I need to specify which database I want to use and how would I do that? My script is below for reference.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'This line stops the worksheet updating on every change, it only updates when cell
'H6 or H7 is touched
If Intersect(Target, Range("H6:H7")) Is Nothing Then Exit Sub
'Set the Variables to be used
Dim pt As PivotTable
Dim Field As PivotField
Dim NewCat As String
'Here you amend to suit your data
Set pt = Worksheets("2018IndSales").PivotTables("PivotTable4")
Set Field = pt.PivotFields("EmployeeName")
NewCat = Worksheets("2018IndSales").Range("H6").Value
'This updates and refreshes the PIVOT table
With Worksheets("2018IndSales").PivotTables("PivotTable4").PivotFields("EmployeeName")
.ClearAllFilters
.PivotFilters.Add Type:=xlCaptionEquals, Value1:=Worksheets("2018IndSales").Range("H6").Value
End With
End Sub
excel vba excel-vba pivot-table
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have used https://www.mrexcel.com/forum/excel-questions/950078-filtering-pivot-table-based-cell-value.html to create the code below but I am getting an error on
Set Field = pt.PivotFields("EmployeeName")
It is saying
Unable to get the PivotFields property of the PivotTable class
Even though EmployeeName
is a field in my pivot table. Now I do have 2 databases in the Data Model that both have EmployeeName
as a field and they are linked via a relationship. Do I need to specify which database I want to use and how would I do that? My script is below for reference.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'This line stops the worksheet updating on every change, it only updates when cell
'H6 or H7 is touched
If Intersect(Target, Range("H6:H7")) Is Nothing Then Exit Sub
'Set the Variables to be used
Dim pt As PivotTable
Dim Field As PivotField
Dim NewCat As String
'Here you amend to suit your data
Set pt = Worksheets("2018IndSales").PivotTables("PivotTable4")
Set Field = pt.PivotFields("EmployeeName")
NewCat = Worksheets("2018IndSales").Range("H6").Value
'This updates and refreshes the PIVOT table
With Worksheets("2018IndSales").PivotTables("PivotTable4").PivotFields("EmployeeName")
.ClearAllFilters
.PivotFilters.Add Type:=xlCaptionEquals, Value1:=Worksheets("2018IndSales").Range("H6").Value
End With
End Sub
excel vba excel-vba pivot-table
I have used https://www.mrexcel.com/forum/excel-questions/950078-filtering-pivot-table-based-cell-value.html to create the code below but I am getting an error on
Set Field = pt.PivotFields("EmployeeName")
It is saying
Unable to get the PivotFields property of the PivotTable class
Even though EmployeeName
is a field in my pivot table. Now I do have 2 databases in the Data Model that both have EmployeeName
as a field and they are linked via a relationship. Do I need to specify which database I want to use and how would I do that? My script is below for reference.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'This line stops the worksheet updating on every change, it only updates when cell
'H6 or H7 is touched
If Intersect(Target, Range("H6:H7")) Is Nothing Then Exit Sub
'Set the Variables to be used
Dim pt As PivotTable
Dim Field As PivotField
Dim NewCat As String
'Here you amend to suit your data
Set pt = Worksheets("2018IndSales").PivotTables("PivotTable4")
Set Field = pt.PivotFields("EmployeeName")
NewCat = Worksheets("2018IndSales").Range("H6").Value
'This updates and refreshes the PIVOT table
With Worksheets("2018IndSales").PivotTables("PivotTable4").PivotFields("EmployeeName")
.ClearAllFilters
.PivotFilters.Add Type:=xlCaptionEquals, Value1:=Worksheets("2018IndSales").Range("H6").Value
End With
End Sub
excel vba excel-vba pivot-table
excel vba excel-vba pivot-table
asked Nov 21 at 17:29
DarrenMcGettigan
257
257
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53417637%2ffilter-a-pivot-table-based-on-cell%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown