Hey All,
So I've been able to identify some factors for an error that is getting thrown in a macro I've written, but I'm really stumped on what is causing it and how to deal with it.
The basics of this macro is to take a range of cells and create a new pivot table. The macro should be able to take any number of rows and columns (typically around 8 columns w/ 100k rows). The code I'm using (and primarily testing with) looks like this
(because this code throws an error, I've also tried)
and 9 times out of 10 this code works fine. However sometimes when running the macro with new data I get an error
"Run-Time error '13':
Type mismatch"
and the debugger points to the code I posted above.
So now I really have no idea what is causing this, so any ideas and help is greatly appreciated. By trying to reproduce the error, my best guess is that the problem is linked to the size of the data, but this is inconsistent (and doesn't make much sense to me).
Results from trying to reproduce error using:
1) Data set 1 - My standard data that I use. Size 12 columns, 110k rows. Has some blank cells. --> This data has worked every time I've run it, with 1 exception as follows. I tried to double the data set (so essential copy-paste the data to the bottom of the set) to make it 220k rows. This then broke the code, pretty much as expected. HOWEVER, deleting the duplicate rows and trying to run the exact same data as I normally do ALSO broke the code. FURTHER, closing without saving and then loading the file again, and using the original data still breaks the code. **Loading an earlier version with identical data and code still works fine.**
2) Data set 2 - A new data set. Size 7 columns, 96k rows. Has more blank cells. Breaks the code the 1st time I ran it. Shrinking it down to ~50k and the code works.
Again, any and all help/suggestions appreciated. Let me know if there is other information I should post to help out.
Thanks,
Arran
So I've been able to identify some factors for an error that is getting thrown in a macro I've written, but I'm really stumped on what is causing it and how to deal with it.
The basics of this macro is to take a range of cells and create a new pivot table. The macro should be able to take any number of rows and columns (typically around 8 columns w/ 100k rows). The code I'm using (and primarily testing with) looks like this
Code:
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
newData, Version:=xlPivotTableVersion12). _
CreatePivotTable TableDestination:=Sheets("Pivot").Cells(8, 1), TableName:="PivotTable1" _
, DefaultVersion:=xlPivotTableVersion12
(because this code throws an error, I've also tried)
Code:
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
Selection). _
CreatePivotTable TableDestination:=Sheets("Pivot").Range("A3"), TableName:="PivotTable1"
and 9 times out of 10 this code works fine. However sometimes when running the macro with new data I get an error
"Run-Time error '13':
Type mismatch"
and the debugger points to the code I posted above.
So now I really have no idea what is causing this, so any ideas and help is greatly appreciated. By trying to reproduce the error, my best guess is that the problem is linked to the size of the data, but this is inconsistent (and doesn't make much sense to me).
Results from trying to reproduce error using:
1) Data set 1 - My standard data that I use. Size 12 columns, 110k rows. Has some blank cells. --> This data has worked every time I've run it, with 1 exception as follows. I tried to double the data set (so essential copy-paste the data to the bottom of the set) to make it 220k rows. This then broke the code, pretty much as expected. HOWEVER, deleting the duplicate rows and trying to run the exact same data as I normally do ALSO broke the code. FURTHER, closing without saving and then loading the file again, and using the original data still breaks the code. **Loading an earlier version with identical data and code still works fine.**
2) Data set 2 - A new data set. Size 7 columns, 96k rows. Has more blank cells. Breaks the code the 1st time I ran it. Shrinking it down to ~50k and the code works.
Again, any and all help/suggestions appreciated. Let me know if there is other information I should post to help out.
Thanks,
Arran