Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
anu anu is offline
external usenet poster
 
Posts: 18
Default MACRO FOR PIVOT TABLE

Hi ,

I want a macro for creating pivot table.However I get an error after a
certain comand (indicated by------)

Following is the set of commands I have typed -

Sheets("Final Sheet").Select
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"'Final Sheet'!R1C1:R1567C43").CreatePivotTable
TableDestination:="", _
TableName:="PivotTable2", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable2").PivotFields ("CODE")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable2").AddDataFiel d
ActiveSheet.PivotTables( _
"PivotTable2").PivotFields("Type"), "Count of Type", xlCount
Range("A3").Select
ActiveSheet.PivotTables("PivotTable2").PivotFields ("Count of Type"). _
Orientation = xlHidden
With ActiveSheet.PivotTables("PivotTable2").PivotFields ("Type")
.Orientation = xlColumnField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable2").AddDataFiel d
ActiveSheet.PivotTables
("PivotTable2").PivotFields("CTRY"), "Count of CTRY", xlCount

----------------------

Sheets("Sheet1").Select
Sheets("Sheet1").Name = "Pre Checks"
Range("A5").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy

Sheets("CHECKS").Select
Range("A2").Select
ActiveSheet.Paste

Can any one help me with this?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default MACRO FOR PIVOT TABLE


You're getting the error because Sheet1 isn't always the next sheet if
you're running this multiple times.
You probably need to add the first 3 lines below somewhere in the
beginning of your code to delete the "old" Pre Checks (Assuming you
don't need it anymore).
Then replace your

Sheets("Sheet1").Select
Sheets("Sheet1").Name = "Pre Checks"
with
ActiveSheet.Name = "Pre Checks"



Code:
On Error Resume Next
Sheets("Pre Checks").Delete
On Error GoTo 0


ActiveSheet.Name = "Pre Checks"


--
pikapika13
------------------------------------------------------------------------
pikapika13's Profile: http://www.excelforum.com/member.php...o&userid=10892
View this thread: http://www.excelforum.com/showthread...hreadid=570770

  #3   Report Post  
Posted to microsoft.public.excel.misc
anu anu is offline
external usenet poster
 
Posts: 18
Default MACRO FOR PIVOT TABLE

Thnx for the help.
However the sheet I am trying to rename is not an existing sheet. It gets
created from pivot table. It is always "SHEET1". I have been careful about
it. I tried to use the commands as given by you but I again land up with
the same error.

"pikapika13" wrote:


You're getting the error because Sheet1 isn't always the next sheet if
you're running this multiple times.
You probably need to add the first 3 lines below somewhere in the
beginning of your code to delete the "old" Pre Checks (Assuming you
don't need it anymore).
Then replace your

Sheets("Sheet1").Select
Sheets("Sheet1").Name = "Pre Checks"
with
ActiveSheet.Name = "Pre Checks"



Code:
On Error Resume Next
Sheets("Pre Checks").Delete
On Error GoTo 0


ActiveSheet.Name = "Pre Checks"


--
pikapika13
------------------------------------------------------------------------
pikapika13's Profile: http://www.excelforum.com/member.php...o&userid=10892
View this thread: http://www.excelforum.com/showthread...hreadid=570770


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
link to combobox legepe Excel Discussion (Misc queries) 4 July 26th 06 04:45 PM
copy excel cell to cell in word table using excel macro jthurnwps Excel Discussion (Misc queries) 0 July 21st 06 07:11 PM
why can't I setup a macro to run Pivot Table? chrisdtran Excel Discussion (Misc queries) 1 March 26th 06 04:17 PM
consolidation of tables in excel with text and figures samenvoegen van sheets Excel Worksheet Functions 8 March 2nd 06 03:27 PM
Macro Help In Excel welshlad Excel Discussion (Misc queries) 14 October 26th 05 02:34 PM


All times are GMT +1. The time now is 12:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"