Cannot add new sheet when drill-down code is active

maek

New Member
Joined
Apr 15, 2011
Messages
4
The drill-down code by Mr. Tom Urtis posted on http://www.mrexcel.com/forum/showthread.php?t=289427
is wonderful. The only problem Im having so far I guess the code somewhat affects the adding of new sheet. I tried in a fresh workbook, I made a pivot table, and double clicked on the pivot table to run the drill-down code below and it's all fine. It's just that I cannot add a new sheet to my workbook. Im using excel 2007.

"Step 1
Place this code in your workbook module. To easily access your workbook module, find the little Excel workbook icon near the upper left corner of your workbook window, usually just to the left of the File menu option. Right click on that icon, left click on View Code, and paste the following procedure into the large white area that is the workbook module. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Code:<o:p></o:p>
Private Sub Workbook_NewSheet(ByVal Sh As Object) <o:p></o:p>
Call DrillDownDefault <o:p></o:p>
End Sub<o:p></o:p>


Step 2
While in the VBE, place this in the worksheet module of the sheet that holds the pivot table: <o:p></o:p>
Code:<o:p></o:p>
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean) <o:p></o:p>
Dim PTT As Integer <o:p></o:p>
On Error Resume Next <o:p></o:p>
PTT = Target.PivotCell.PivotCellType <o:p></o:p>
If Err.Number = 1004 Then <o:p></o:p>
Err.Clear <o:p></o:p>
Else <o:p></o:p>
CS = ActiveSheet.Name <o:p></o:p>
End If <o:p></o:p>
End Sub<o:p></o:p>


Step 3
Also while in the VBE, place this in a standard VBA module: <o:p></o:p>
Code:<o:p></o:p>
Public CS As String <o:p></o:p>
<o:p></o:p>
Sub DrillDownDefault() <o:p></o:p>
With Application <o:p></o:p>
.ScreenUpdating = False <o:p></o:p>
Dim LR As Long <o:p></o:p>
LR = Sheets(CS).Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 2 <o:p></o:p>
Range("A1").CurrentRegion.Copy Sheets(CS).Cells(LR, 1) <o:p></o:p>
.DisplayAlerts = False <o:p></o:p>
ActiveSheet.Delete <o:p></o:p>
.DisplayAlerts = True <o:p></o:p>
Sheets(CS).Select <o:p></o:p>
.ScreenUpdating = True <o:p></o:p>
End With <o:p></o:p>
End Sub<o:p></o:p>


Step 4
Press Alt+Q to return to the worksheet.


Now, as you double-click the Data section of the pivot table, that target cell's drill-down dataset will be stacked vertically in order of the drill-downs, below and on the same sheet as the pivot table.

Another cool feature:
If, after creating a drill-down data set, yo no longer want to see it on that sheet, simply double click any cell in that data set's range and it will be deleted from the sheet."

Your help or any tweaks on the code above so as not to affect the adding a new sheet function is very much appreciated.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Forum statistics

Threads
1,223,264
Messages
6,171,081
Members
452,377
Latest member
bradfordsam

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