LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Query then pivot table

I had an interesting problem today. A posting had a SQL Query in a macro
then wanted to create a Pivot table. The user also want to be able to
refresh the query and update the pivot table.

Since the number of the rows of the query can change the datasource of the
pivot table would also change; the datasource of the query table also needs
to be changed after the query was updated.

The problem is the Pivot Table Datasource is in R1C1 addressing

Can anybody figure out how in VBA to refernce R1C1 address

set MyRange = Range("Sheet2!R1C1:R6C4") doesn't work

neither does
set Myrange = Evaluate("indirect(Sheet2!R1C1:R6C4,false)")

I ended up doing the following

MyRange = "Sheet2!R1C1:R6C4"
'Remove Sheet Name
MySht = MyRange = Left(Myrange,Instr(MyRange,"!") - 1)
'remove sheet and first R from R1C1 address
MySht = MyRange = Left(Myrange,Instr(MyRange,"!") + 2)
FirstRow = Val(MyRange)
MyRange = mid(Myrange,Instr(MyRange,"C") + 1)
FirstCol = Val(MyRange)
MyRange = mid(Myrange,Instr(MyRange,"R") + 1)
LastRow = Val(MyRange)
MyRange = mid(Myrange,Instr(MyRange,"C") + 1)
LastCol = Val(MyRange)

with Sheets(MySht)
Set MyRange = .Range(.Cells(FirstRow,FirstCol),.Cells(LastRow,La stCol))
end with
 
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
a query for pivot table Arvind Excel Discussion (Misc queries) 1 January 25th 08 02:32 PM
Pivot Table From MS Query JH Palmer Excel Programming 0 October 18th 07 02:26 PM
Pivot Table Query Lee White Excel Discussion (Misc queries) 1 January 30th 07 01:07 PM
Pivot Table Query sgriff Excel Discussion (Misc queries) 0 July 21st 06 08:08 AM
Pivot Table Query Frank Excel Programming 2 May 17th 05 11:37 AM


All times are GMT +1. The time now is 02:22 AM.

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"