Here is the code, not sure I can replicate the behaviour in a sample notebook
Dim Salesperson As String
Dim myrange As Range
'this is the sales querytable and C is the column with the salespeople. A salesperson _
may be listed twice (sales from 2009 and from 2010)
Set myrange = Sheet1.Range("C:C")
If Sheet8.CL_SalesPersonLookup.Value = "" Then
Exit Sub
End If
Salesperson = Sheet8.CL_SalesPersonLookup.Value
Dim isitthere As Boolean
Dim there As String
isitthere = True
On Error Resume Next
there = Application.WorksheetFunction.Match(Salesperson, myrange, 0)
If Err.Number <> 0 Then
isitthere = False
Else
isitthere = True
End If
Dim Worksheet As Worksheet
Set Worksheet = ThisWorkbook.Worksheets("Salesperson Lookup Feature")
For Each PivotTable In Worksheet.PivotTables
With PivotTable
.PivotCache.MissingItemsLimit = xlMissingItemsNone
.PivotCache.Refresh
If isitthere = True Then
.PivotFields("Salesperson Name").CurrentPage = Salesperson
Else
If PivotTable.SourceData = "SalesQuery" Then
.PivotFields("Salesperson Name").CurrentPage = Salesperson
Else
.PivotFields("Salesperson Name").CurrentPage = "(All)"
End If
End If
.RefreshTable
End With
Next PivotTable
For Each PivotTable In Worksheet.PivotTables
With PivotTable
Dim rng As Range
If .PivotFields("Salesperson Name").CurrentPage = "(All)" Then
For Each rng In .DataBodyRange.Cells
rng.Font.ColorIndex = 2
Next rng
Else
For Each rng In .DataBodyRange.Cells
rng.Font.ColorIndex = xlAutomatic
Next rng
End If
End With
Next PivotTable
Set Worksheet = Nothing
Dim objCht As ChartObject
Dim seriescoll As SeriesCollection
Set shtTemp = Sheet8
Dim i As Integer
For Each objCht In shtTemp.ChartObjects
With objCht.Chart
If .PivotLayout.PivotTable.PivotFields("Salesperson Name").CurrentPage = "(All)" Then
For i = 1 To objCht.Chart.SeriesCollection.Count
With objCht.Chart.SeriesCollection(i)
.Border.Weight = xlThin
.Border.LineStyle = xlNonese
.Interior.ColorIndex = 2
.Interior.Pattern = xlSolid
End With
Next
Else
For i = 1 To objCht.Chart.SeriesCollection.Count
With objCht.Chart.SeriesCollection(i)
.Border.ColorIndex = 57
.Border.Weight = xlThin
.Border.LineStyle = xlContinuous
.Interior.ColorIndex = xlAutomatic
.Interior.Pattern = xlSolid
End With
Next
End If
End With
Next objCht
If isitthere = False Then
MsgBox "This person has no sales"
End If
so what my issue is, is that sometimes, I'll put "John Smith" in the combobox (Sheet8.CL_SalesPersonLookup.Value) and the pivottable page field will say "John Smith" but the data will reflect the sales of "Jennifer Garner". And when I drill down to the raw data (with it creating a new sheet) the salesperson in the column will be "Jennifer Garner"
it happens sporatically. I first noticed it always happened with a person named with the following syntax: firstname * lastname. Althought I don't think the asterisk does anything to muck up my results. It happens often enough that I don't trust it anymore
Bookmarks