Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default pass worksheet name to a macro

Hi,

I recorded a macro to create a pivot table for a worksheet. but I
want use this macro for more than one worksheet, that individual
worksheet name is required to pass to this macro. Could you please
give some me some ideas on how to pass the worksheet name to the macro?

Thanks!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default pass worksheet name to a macro

Allan wrote:
Hi,

I recorded a macro to create a pivot table for a worksheet. but I
want use this macro for more than one worksheet, that individual
worksheet name is required to pass to this macro. Could you please
give some me some ideas on how to pass the worksheet name to the macro?

Thanks!


Post your macro here. Or at least begining of it.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default pass worksheet name to a macro


witek wrote:
Post your macro here. Or at least begining of it.



Sub Macro1()
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:=
_
"'Sheet1'!R5C1:R138C5").CreatePivotTable TableDestination:="",
_
TableName:="PivotTable1"
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3,
1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable1").SmallGrid = False
ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:= _
"Name", ColumnFields:="Level"

ActiveSheet.PivotTables("PivotTable1").PivotFields ("Count").Orientation
= _
xlDataField
End Sub

How to make this code to handle : Sheet1, Sheet2 ...... with their
ranges ? Thank you!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default pass worksheet name to a macro

Allan,
I don't use pivot table, but you need to pass in any required info, using
those objects in place of the current "ActiveWorkbook", "ActiveSheet" etc.
So:

Sub MakePivot(argSheet as Worksheet, argDataRange as
range,argDestinationRange as range)
With argSheet.Parent
.PivotCaches.Add(SourceType:=xlDatabase, SourceData:="'" & argSheet.name
& "'!" & argDataRange.address.....
etc

NickHK

"Allan" wrote in message
ups.com...

witek wrote:
Post your macro here. Or at least begining of it.



Sub Macro1()
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:=
_
"'Sheet1'!R5C1:R138C5").CreatePivotTable TableDestination:="",
_
TableName:="PivotTable1"
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3,
1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable1").SmallGrid = False
ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:= _
"Name", ColumnFields:="Level"

ActiveSheet.PivotTables("PivotTable1").PivotFields ("Count").Orientation
= _
xlDataField
End Sub

How to make this code to handle : Sheet1, Sheet2 ...... with their
ranges ? Thank you!



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
pass to textbox on a form and to excel worksheet cvw New Users to Excel 0 March 16th 10 07:35 PM
Pass contents of a cell to a macro Steve Excel Programming 3 February 17th 06 10:56 AM
Pass variable to macro Jason Morin Excel Programming 2 November 28th 05 04:13 PM
Pass worksheet to macro as a parameter Przemek Excel Programming 1 July 12th 05 05:50 PM
pass argument to macro tommy Excel Programming 4 September 1st 04 06:21 PM


All times are GMT +1. The time now is 09:22 PM.

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

About Us

"It's about Microsoft Excel"