View Single Post
  #2   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


"Grant" wrote in 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


pvtTable is an object and the PivotTables(x) takes a string or number. What
you want to say here is

pvTable.PivotFields("Line").CurrentPage = str

That's the whole liine.

Next pvtTable


When you use PivotTables(x), you are really using the Item property of the
PivotTables collection object. It's the same as saying

PivotTables.Item(x)

Item is the default property for collection objects, so you don't have to
type it.


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