chergh
blah
- Local time
- Today, 15:09
- Joined
- Jun 15, 2004
- Messages
- 1,414
Hi Folks,
I am trying to pass variables to a sub which creates a pivottable.
The following line of code works:
I want to create multiple pivottables so I created a seperate sub and intend to pass information to them. I have tried doing it as follows but it doesn't work:
I have defined these as strings I then call the sub which creates the pivottable as follows:
Here is the start of the sub for creating the pivot tables:
And here is the line where I have the problem:
Here the code breaks and I get Run-time error '1004': AddFields method of the pivottable class failed.
As the text string looks right when I use a message box to look at it I am guessing that passing this stuff as a string is completely the wrong way to do it.
This is a cut down version of the code and will post it all should anyone think it necessary.
Anyone able to help?
I am trying to pass variables to a sub which creates a pivottable.
The following line of code works:
Code:
pt.AddFields RowFields:=Array("BG_DETECTION_DATE", "BG_SEVERITY"), ColumnFields:=Array("BG_PROJECT_DB", "BG_USER_01")
I want to create multiple pivottables so I created a seperate sub and intend to pass information to them. I have tried doing it as follows but it doesn't work:
Code:
dim row_fields as String
dim column_fields as string
Row_Fields = """BG_DETECTION_DATE"", ""BG_SEVERITY"""
Column_Fields = """BG_PROJECT_DB"", ""BG_USER_01"""
I have defined these as strings I then call the sub which creates the pivottable as follows:
Code:
Call pt_td_metrics(Row_Fields, _
Column_Fields)
Here is the start of the sub for creating the pivot tables:
Code:
Sub pt_td_metrics(Row_Fields As String, _
Column_Fields As String)
And here is the line where I have the problem:
Code:
pt.AddFields RowFields:=Array(Row_Fields), ColumnFields:=Array(Column_Fields)
Here the code breaks and I get Run-time error '1004': AddFields method of the pivottable class failed.
As the text string looks right when I use a message box to look at it I am guessing that passing this stuff as a string is completely the wrong way to do it.
This is a cut down version of the code and will post it all should anyone think it necessary.
Anyone able to help?