Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type Mismatch

Status
Not open for further replies.

b00buu

Programmer
Feb 4, 2003
3
US
I am attempting to manipulate an existing excel pivot table using vbscript. I want to group the pivot table by 7 day weeks. I can sucessfully group by months but when I try to group by days I get a type mismatch error.

The script I am using is below:

myArray = Array(FALSE,FALSE,FALSE,TRUE,FALSE,FALSE,FALSE)
Set objXL = WScript.CreateObject("Excel.Application")
objXL.Visible = FALSE
objXL.DisplayAlerts = FALSE
objXL.Workbooks.Open("c:\temp\weekly.xls")
Set objSheet = objXL.ActiveWorkBook.Sheets.Item(1)
Set objPivot = objSheet.PivotTables(1)
Set groupRange = objPivot.PivotFields("DataDate").DataRange

' groups by months sucessfully
' groupRange.Cells(1).Group

' group by weeks fails with a type mismatch error
groupRange.Cells(1).Group by=7, periods=MyArray

objXL.ActiveWorkBook.Save()
objXL.Quit()

Thank you in advance
 
try it with the following syntax:

groupRange.Cells(1).Group(Start, End, By, Periods)
Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
Thank you for your response.

When I use
groupRange.Cells(1).Group(TRUE,TRUE,7,MyArray)

I get the vbScript compilation error "Cannot use parenthesis when calling a sub"

and when I use

groupRange.Cells(1).Group(Start=TRUE, End=TRUE, By=7, Periods=MyArray)
I get the vbScript compilation error "Syntax Error"

 
Thank you so much. That worked. It has been driving me slowly mad.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top