PC Review


Reply
Thread Tools Rate Thread

Creating Pivot tables by VBA for varying amounts of data

 
 
Paul
Guest
Posts: n/a
 
      10th Dec 2006
Hi all,

I have to create a number of pivot tables from the same block of data, and
repeat this with new data four weeks later etc. Data is always in the range
("A3:V" & x) where x varies each 4 weeks.
I have successfully in the past substituted "selection" for the R1C1 range
created in a recorded macro for

'ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase,
SourceData:=Selection)'

but this is now coming up with a "type mismatch" error.
If anyone has any ideas I would be very grateful. I am using Office XP.

TIA

Paul

--
Paul at preeve dot plus dot com


 
Reply With Quote
 
 
 
 
Tom Ogilvy
Guest
Posts: n/a
 
      10th Dec 2006
Dim rng as Range
With Worksheets("Data")
set rng = .Range(.Cells(3,1),.Cells(rows.count,1).End(xlup))
End with
set rng = rng.Resize(,22)
ActiveWorkbook.PivotCaches.Add( _
SourceType:=xlDatabase, _
SourceData:=rng.Address(1,1,xlR1C1,True)

--
Regards,
Tom Ogilvy


"Paul" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi all,
>
> I have to create a number of pivot tables from the same block of data, and
> repeat this with new data four weeks later etc. Data is always in the
> range ("A3:V" & x) where x varies each 4 weeks.
> I have successfully in the past substituted "selection" for the R1C1 range
> created in a recorded macro for
>
> 'ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase,
> SourceData:=Selection)'
>
> but this is now coming up with a "type mismatch" error.
> If anyone has any ideas I would be very grateful. I am using Office XP.
>
> TIA
>
> Paul
>
> --
> Paul at preeve dot plus dot com
>



 
Reply With Quote
 
Paul
Guest
Posts: n/a
 
      11th Dec 2006
thanks Tom, I'll try that in the office tomorrow

Paul

--
Paul at preeve dot plus dot com
"Tom Ogilvy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Dim rng as Range
> With Worksheets("Data")
> set rng = .Range(.Cells(3,1),.Cells(rows.count,1).End(xlup))
> End with
> set rng = rng.Resize(,22)
> ActiveWorkbook.PivotCaches.Add( _
> SourceType:=xlDatabase, _
> SourceData:=rng.Address(1,1,xlR1C1,True)
>
> --
> Regards,
> Tom Ogilvy
>
>
> "Paul" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Hi all,
>>
>> I have to create a number of pivot tables from the same block of data,
>> and repeat this with new data four weeks later etc. Data is always in the
>> range ("A3:V" & x) where x varies each 4 weeks.
>> I have successfully in the past substituted "selection" for the R1C1
>> range created in a recorded macro for
>>
>> 'ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase,
>> SourceData:=Selection)'
>>
>> but this is now coming up with a "type mismatch" error.
>> If anyone has any ideas I would be very grateful. I am using Office XP.
>>
>> TIA
>>
>> Paul
>>
>> --
>> Paul at preeve dot plus dot com
>>

>
>



 
Reply With Quote
 
Paul
Guest
Posts: n/a
 
      12th Dec 2006
....and it worked fine. Thanks again

--
Paul at preeve dot plus dot com
"Paul" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> thanks Tom, I'll try that in the office tomorrow
>
> Paul
>
> --
> Paul at preeve dot plus dot com
> "Tom Ogilvy" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Dim rng as Range
>> With Worksheets("Data")
>> set rng = .Range(.Cells(3,1),.Cells(rows.count,1).End(xlup))
>> End with
>> set rng = rng.Resize(,22)
>> ActiveWorkbook.PivotCaches.Add( _
>> SourceType:=xlDatabase, _
>> SourceData:=rng.Address(1,1,xlR1C1,True)
>>
>> --
>> Regards,
>> Tom Ogilvy
>>
>>
>> "Paul" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> Hi all,
>>>
>>> I have to create a number of pivot tables from the same block of data,
>>> and repeat this with new data four weeks later etc. Data is always in
>>> the range ("A3:V" & x) where x varies each 4 weeks.
>>> I have successfully in the past substituted "selection" for the R1C1
>>> range created in a recorded macro for
>>>
>>> 'ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase,
>>> SourceData:=Selection)'
>>>
>>> but this is now coming up with a "type mismatch" error.
>>> If anyone has any ideas I would be very grateful. I am using Office XP.
>>>
>>> TIA
>>>
>>> Paul
>>>
>>> --
>>> Paul at preeve dot plus dot com
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a chart with varying data value ranges Anthony Blackburn Microsoft Excel Misc 1 17th May 2010 05:41 PM
Code to delete rows with varying amounts of data Zakynthos Microsoft Excel Programming 2 13th Apr 2010 11:39 AM
RE: How to design tables for grid-like data of varying types? Fred Microsoft Access 0 28th May 2008 12:49 PM
compare data from two tables with varying record numbers british521 Microsoft Excel Worksheet Functions 0 30th Jan 2008 08:01 PM
getting data from an array of varying amounts of comboboxes lar.thegreat@gmail.com Microsoft Excel Programming 1 20th Jun 2007 06:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:26 AM.