macro comment used in 2003 excel not working in 2010
-
- 2StarLounger
- Posts: 113
- Joined: 09 Jan 2014, 10:06
- Location: Chennai, Tamil nadu, india.
macro comment used in 2003 excel not working in 2010
Hi
i use the below comment to create the pivot in 2003 excel but it is not worling in 2010 vision kindly help.
Sheets("base").Select
rn1 = Cells.Find(What:="*", after:=Range("a1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
Dim myrange1 As Range
Set myrange1 = Sheets("base").Range("A1:H" & rn1)
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
myrange1).CreatePivotTable _
TableDestination:="", TableName:="PivotTable1", DefaultVersion _
:=xlPivotTableVersion14
Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("GL Amount"), "Sum of GL Amount", xlSum
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Sum of GL Amount")
.NumberFormat = "0.00_);(0.00)"
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Batch #")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("GL Code")
.Orientation = xlRowField
.Position = 2
End With
ActiveSheet.PivotTables("PivotTable1").PivotFields("Batch #").Subtotals = Array _
(False, False, False, False, False, False, False, False, False, False, False, False)
ActiveWorkbook.ShowPivotTableFieldList = False
i use the below comment to create the pivot in 2003 excel but it is not worling in 2010 vision kindly help.
Sheets("base").Select
rn1 = Cells.Find(What:="*", after:=Range("a1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
Dim myrange1 As Range
Set myrange1 = Sheets("base").Range("A1:H" & rn1)
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
myrange1).CreatePivotTable _
TableDestination:="", TableName:="PivotTable1", DefaultVersion _
:=xlPivotTableVersion14
Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("GL Amount"), "Sum of GL Amount", xlSum
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Sum of GL Amount")
.NumberFormat = "0.00_);(0.00)"
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Batch #")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("GL Code")
.Orientation = xlRowField
.Position = 2
End With
ActiveSheet.PivotTables("PivotTable1").PivotFields("Batch #").Subtotals = Array _
(False, False, False, False, False, False, False, False, False, False, False, False)
ActiveWorkbook.ShowPivotTableFieldList = False
-
- Administrator
- Posts: 78412
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: macro comment used in 2003 excel not working in 2010
Do you get an error message? If so, what does it say and on which line does it occur?
Best wishes,
Hans
Hans
-
- 2StarLounger
- Posts: 113
- Joined: 09 Jan 2014, 10:06
- Location: Chennai, Tamil nadu, india.
Re: macro comment used in 2003 excel not working in 2010
the Error is Run time ERROR 13
Type MISMATCH
Yellow highlited line is below:-
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
myrange1).CreatePivotTable _
TableDestination:="", TableName:="PivotTable1", DefaultVersion _
:=xlPivotTableVersion10
Type MISMATCH
Yellow highlited line is below:-
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
myrange1).CreatePivotTable _
TableDestination:="", TableName:="PivotTable1", DefaultVersion _
:=xlPivotTableVersion10
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: macro comment used in 2003 excel not working in 2010
Give this version a try...
Code: Select all
Sheets("base").Select
rn1 = Cells.Find(What:="*", after:=Range("a1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
Dim myrange1 As Range
Set myrange1 = Sheets("base").Range("A1:H" & rn1)
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=myrange1, _
Version:=xlPivotTableVersion14).CreatePivotTable TableDestination:="", _
TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion14
Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("GL Amount"), "Sum of GL Amount", xlSum
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Sum of GL Amount")
.NumberFormat = "0.00_);(0.00)"
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Batch #")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("GL Code")
.Orientation = xlRowField
.Position = 2
End With
ActiveSheet.PivotTables("PivotTable1").PivotFields("Batch #").Subtotals = Array _
(False, False, False, False, False, False, False, False, False, False, False, False)
ActiveWorkbook.ShowPivotTableFieldList = False
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- 2StarLounger
- Posts: 113
- Joined: 09 Jan 2014, 10:06
- Location: Chennai, Tamil nadu, india.
Re: macro comment used in 2003 excel not working in 2010
same error is poping up
type mismatch
Yellow highlited line below
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=myrange1, _
Version:=xlPivotTableVersion14).CreatePivotTable TableDestination:="", _
TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion14
type mismatch
Yellow highlited line below
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=myrange1, _
Version:=xlPivotTableVersion14).CreatePivotTable TableDestination:="", _
TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion14
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: macro comment used in 2003 excel not working in 2010
It runs on my PC without a problem. (I am using Excel 2013 though!)
Try changing the Version:=xlPivotTableVersion14 to Version:=xlPivotTableVersion10
Also, if it does not work with PivotCaches.Create, try PivotCaches.Add again!
Try changing the Version:=xlPivotTableVersion14 to Version:=xlPivotTableVersion10
Also, if it does not work with PivotCaches.Create, try PivotCaches.Add again!
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- Administrator
- Posts: 78412
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: macro comment used in 2003 excel not working in 2010
The problem is that you don't specify the TableDestination. Try this, for example:
Code: Select all
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=myrange1).CreatePivotTable _
TableDestination:=Range("K3"), TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion14
Best wishes,
Hans
Hans
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: macro comment used in 2003 excel not working in 2010
If no table destination is supplied it seems to default to cell A1 of a new sheet.
Further experiments seem to work if the Version arguments are removed.
If the code above does not work, try this version without the Version arguments. (It also works without debugs in Excel 2013)
Further experiments seem to work if the Version arguments are removed.
If the code above does not work, try this version without the Version arguments. (It also works without debugs in Excel 2013)
Code: Select all
Sheets("base").Select
rn1 = Cells.Find(What:="*", after:=Range("a1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
Dim myrange1 As Range
Set myrange1 = Sheets("base").Range("A1:H" & rn1)
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=myrange1) _
.CreatePivotTable TableDestination:="", TableName:="PivotTable1"
Cells(1, 1).Select
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("GL Amount"), "Sum of GL Amount", xlSum
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Sum of GL Amount")
.NumberFormat = "0.00_);(0.00)"
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Batch #")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("GL Code")
.Orientation = xlRowField
.Position = 2
End With
ActiveSheet.PivotTables("PivotTable1").PivotFields("Batch #").Subtotals = Array _
(False, False, False, False, False, False, False, False, False, False, False, False)
ActiveWorkbook.ShowPivotTableFieldList = False
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- Administrator
- Posts: 78412
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: macro comment used in 2003 excel not working in 2010
I consistently got an error message if "" is specified as TableDestination...Rudi wrote:If no table destination is supplied it seems to default to cell A1 of a new sheet.
Best wishes,
Hans
Hans
-
- Microsoft MVP
- Posts: 656
- Joined: 24 Jan 2010, 17:51
- Status: Microsoft MVP
- Location: Weert, The Netherlands
Re: macro comment used in 2003 excel not working in 2010
Confirmed, if tabledestination is omitted, Excel 2010 errors out (even though recording a macro records it as "")
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: macro comment used in 2003 excel not working in 2010
That is strange...To confirm, you are using Excel 2013, right? Jan Karel confirms that 2010 debugs, but my 2013 runs the code fine.HansV wrote:I consistently got an error message if "" is specified as TableDestination...Rudi wrote:If no table destination is supplied it seems to default to cell A1 of a new sheet.
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- Administrator
- Posts: 78412
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: macro comment used in 2003 excel not working in 2010
Does this workbook error for you? It runs fine for me... (just out of interest)?
You do not have the required permissions to view the files attached to this post.
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- Administrator
- Posts: 78412
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: macro comment used in 2003 excel not working in 2010
I'll check later (I'm on another computer at the moment)
Best wishes,
Hans
Hans
-
- Microsoft MVP
- Posts: 656
- Joined: 24 Jan 2010, 17:51
- Status: Microsoft MVP
- Location: Weert, The Netherlands
Re: macro comment used in 2003 excel not working in 2010
Seems to work fine on my Excel 2010.
-
- Administrator
- Posts: 78412
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: macro comment used in 2003 excel not working in 2010
Rudi, your macro works for me in Excel 2013 too - it does create a new sheet for the pivot table. Mysterious...
Best wishes,
Hans
Hans
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: macro comment used in 2003 excel not working in 2010
Thanks for confirming guys.
Mysterious is the operative word!
However, it is all up to jawahars with plenty of feedback to review...
Mysterious is the operative word!
However, it is all up to jawahars with plenty of feedback to review...
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.