View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Dick Kusleika[_3_] Dick Kusleika[_3_] is offline
external usenet poster
 
Posts: 599
Default Type Mismatch error

Grant

How many pivottables are on the sheet? In the Immediate window type

?Sheet1.PivotTables.Count

where sheet1 is the codename for the sheet in question. Do that even if you
think you know how many there are. It has to be that there is no Line pivot
field or that the Line pivot field is not a page field for one of the
pivottables on the sheet.

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

"Grant" wrote in message
...
This is really strange. I can get the following code to
work:
ActiveSheet.PivotTables("PvtFTE").PivotFields
("Line").CurrentPage = sStr


but not:

For Each pvtTable In ActiveWorkbook.Worksheets
(wkSheet.Name).PivotTables
With pvtTable
.PreserveFormatting = True
.PivotFields("Line").CurrentPage = sStr
End With
Next pvtTable


Any ideas?
Thanks,
Grant.


-----Original Message-----
Hello, I get a type mismatch error with the following
code but can't see where I am going wrong. Can anyone
help please? Thanks.


For Each pvtTable In ActiveWorkbook.Worksheets _
(wkSheet.Name).PivotTables
pvtTable.PreserveFormatting = True
Worksheets(wkSheet).PivotTables _
(pvtTable).PivotFields("Line").CurrentPage = str
Next pvtTable

.