Pivot tables - position on sheet

ajm

Well-known Member
Joined
Feb 5, 2003
Messages
1,975
Office Version
  1. 365
Platform
  1. Windows
hi all, am needing to add a second pivot table to each of my existing reports and want it t be offset from the first so that any changes in the first will move the second also. essentially, the second pivot will be in column C starting 5 rows beneath the first pivot table. can't seem top find any posts on the topic??

also, why does my formula:

=OFFSET(Import!$a$1,0,0,COUNTA(Import!B:B),COUNTA(Import!1:1))

not produce the named range it should?
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
The few times I've tried that, it has either been with a defined and unchanging number of row items or by allowing enough rows for the top PT to expand without crashing into adjacent tables. I don't know of a way to make a PT gracefully move a second PT, so my approach would be to leave, say, 150 blank rows between the tables and hide the empty rows to give the correct visual spacing.

EDIT -- Second question -- Are there any gaps in column B? Do you get a range that's a few rows short, or don't you get a range at all?

Denis
 
Last edited:
Upvote 0
Agree with Denis - easier to allow for expansion than attempt to capture it. That said, I was just playing around with this. Not fully tested, and I'm sure there are better methods, but this will insert a blank column and / or row around the Pivot Table if it finds values it its way.

Code:
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
Dim ws As Worksheet
Dim rngCornerBR, rngCornerTR, rngCornerBL As Range
 
With Target
   Set ws = .Parent
   Set rngCornerBR = ws.Cells(.TableRange1.Rows.Count + .TableRange1.Row, .TableRange1.Columns.Count + .TableRange1.Column)
   Set rngCornerTR = ws.Cells(.TableRange1.Row, .TableRange1.Columns.Count + .TableRange1.Column)
   Set rngCornerBL = ws.Cells(.TableRange1.Rows.Count + .TableRange1.Row, .TableRange1.Column)
End With
 
 
On Error Resume Next
 
If WorksheetFunction.CountA(Range(rngCornerTR, rngCornerBR)) > 0 Then rngCornerBR.EntireColumn.Insert
If Err = 1004 Then
    MsgBox "Could not insert a column as there is another pivot table spanning column " & rngCornerBR.Column, _
    vbOKOnly + vbInformation, "Trying to make space around " & Target.Name
End If
 
If WorksheetFunction.CountA(Range(rngCornerBL, rngCornerBR)) > 0 Then rngCornerBR.EntireRow.Insert
If Err = 1004 Then
    MsgBox "Could not insert a row as there is another pivot table spanning row " & rngCornerBR.Row, _
    vbOKOnly + vbInformation, "Trying to make space around " & Target.Name
 
End If
 
End Sub
 
Upvote 0
thanks guys. will try pivot stuff this morning, kids allowing. and denis, no range shows up at all. nitind showed me a method of resizing an existing named range a month or two ago which i will use in the meantime. however, i would loive to know why this doesn't work as it really should. no blank cells in the count range in either direction. ??? anyway, i was thinking i might be a way of naming the range that contains the pivot and then i could offset from the bottom row of that.
 
Last edited:
Upvote 0
Just looked again. The range reference should be absolute, or else it moves around and you will get nothing. Change to:

=OFFSET(Import!$a$1,0,0,COUNTA(Import!$B:$B),COUNTA(Import!$1:$1))

Denis
 
Upvote 0

Forum statistics

Threads
1,203,632
Messages
6,056,452
Members
444,866
Latest member
cr130

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top