Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,979
Default how do I hard code a variable range for a pivot table in vba?

You could use a dynamic range as the pivot source, and refer to the
range name in the code. There are instructions he

http://www.contextures.com/xlPivot01.html


havocdragon wrote:
Hey all. I have noticed that Pivot Tables when programmed in visual basic
seem to be more picky than some other code. And honestly I dont write much of
the code myself but know where the key fields I need to change are. Here is
my current code

Range("A1").select
Selection.CurrentRegion.Select

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _
"'Report'!R1C1:R797C12").CreatePivotTable TableDestination:="", _
TableName:="Report"

now if this is hard coded it is going to select A$1$:L$797$ everytime. I
want that to be the current region or selection, or utilize the
selection.currentregion.select in that code itself so this will work no
matter how many columns or rows of info there are, it will only create a
pivot table based on those regions.



--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html

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
Pivot table with a variable range in the sourcedata field [email protected] Excel Discussion (Misc queries) 2 January 31st 07 12:11 AM
Pivot Table variable range La Durande Excel Programming 1 October 18th 04 08:42 PM
Im so close. Need variable range for the pivot table Loren[_2_] Excel Programming 1 October 5th 04 10:53 PM
Change hard code to Variable syntax Orlando Magalhães Filho Excel Programming 1 September 13th 03 07:36 AM
Change hard code to Variable syntax Bob Phillips[_5_] Excel Programming 0 September 13th 03 07:32 AM


All times are GMT +1. The time now is 09:14 AM.

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"