Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default VB Help If Statement in Selection.ShowDetail = True

You were getting an error because the selected cell was not inside a pivot
table. I'm not sure if this is the simpliest method to determine if a cell
is inside a pivot table. but it seem to prevent errors. Not sure if it does
what you want. I concerned wit your original code. Are you using a Pivot
table chart?


Sub getdata()
'
' getdata Macro
'
' Keyboard Shortcut: Ctrl+q
'

ColCount = 3
BookCount = 1
ChDir "C:\temp\test"

'check each worksheet
For Each sht In ThisWorkbook.Sheets
'check if pivot table is in range of selected cell
Found = False
'look at each pivot table on worksheet
For Each piv In sht.PivotTables
'covert address of pivot table from R1C1 to A1
Pivaddr = Application.ConvertFormula( _
Formula:=piv.SourceData, _
fromReferenceStyle:=xlR1C1, _
toReferenceStyle:=xlA1)
'remove sheet name from pivot table address
Pivaddr = Mid(Pivaddr, InStr(Pivaddr, "!") + 1)
'check if intersection of pivot table and cell address match
Set IsPivotTable = Application.Intersect(sht.Range(Pivaddr), _
sht.Cells(7, ColCount))

'exit loop if cell address is inside a pivot table
If Not IsPivotTable Is Nothing Then
Found = True
Exit For
End If
Next piv

'if cell address is inside a pivot table
If Found = True Then

'show details
sht.Cells(7, ColCount).ShowDetail = True
'save workbook
ActiveWorkbook.SaveAs Filename:="C:\test\" & BookCount & ".csv", _
FileFormat:=xlCSV, _
CreateBackup:=False
BookCount = BookCount + 1
ColCount = ColCount + 3
End If
Next sht
End Sub


"TroyT" wrote:

Also when i add it to the file with the Pivot tables it gives me an error at
the same location..
Unable to set the ShowDetal property of the Range Class. RunTime Error 1004

"TroyT" wrote:

It fails on
sht.Cells(7, ColCount).ShowDetail = True

Im trying to run this in Excel 2007, and I am saving this macro in a macro
enabled workbook, which is always open. Then opening the file i need to get
the data from the pivot table. Is this the best way to do it? I can kinda
follow what you are doing, but i am still lost..

Thanks for your help..

"Joel" wrote:

I had i instead of bookcount

Sub getdata()
'
' getdata Macro
'
' Keyboard Shortcut: Ctrl+q
'

ColCount = 3
BookCount = 1
ChDir "C:\test"
For Each sht In ThisWorkbook.Sheets
On Error GoTo 100
sht.Cells(7, ColCount).ShowDetail = True
ActiveWorkbook.SaveAs Filename:="C:\test\" & BookCount & ".csv", _
FileFormat:=xlCSV, _
CreateBackup:=False
BookCount = BookCount + 1
100 ColCount = ColCount + 3
Next sht
End Sub


"TroyT" wrote:

Hello,
I have recorded almost what I need and hoped you guys here would be able to
help me. This Macro will
Drill down into 8 specifically placed pivot tables on a single worksheet,
and save the individual files to c:\test.csv

The macro works if every pivot table has data, but if its blank it fails.
Also, i need help in making the file names change. It could be previous +1
or anything as long as there is never a duplicate..
Here is the macro.

Sub getdata()
'
' getdata Macro
'
' Keyboard Shortcut: Ctrl+q
'
Range("C7").Select
Selection.ShowDetail = True
ChDir "C:\test"
ActiveWorkbook.SaveAs Filename:="C:\test\1.csv", FileFormat:=xlCSV, _
CreateBackup:=False
ActiveSheet.Next.Select
Range("F7").Select
Selection.ShowDetail = True
ActiveWorkbook.SaveAs Filename:="C:\test\2.csv", FileFormat:=xlCSV, _
CreateBackup:=False
ActiveSheet.Next.Select
Range("I7").Select
Selection.ShowDetail = True
ActiveWorkbook.SaveAs Filename:="C:\test\3.csv", FileFormat:=xlCSV, _
CreateBackup:=False
ActiveSheet.Next.Select
Range("L7").Select
Selection.ShowDetail = True
ActiveWorkbook.SaveAs Filename:="C:\test\4.csv", FileFormat:=xlCSV, _
CreateBackup:=False
ActiveSheet.Next.Select
Range("O7").Select
Selection.ShowDetail = True
ActiveWorkbook.SaveAs Filename:="C:\test\5.csv", FileFormat:=xlCSV, _
CreateBackup:=False
ActiveSheet.Next.Select
Range("R7").Select
Selection.ShowDetail = True
ActiveWorkbook.SaveAs Filename:="C:\test\6.csv", FileFormat:=xlCSV, _
CreateBackup:=False
ActiveSheet.Next.Select
Range("U7").Select
Selection.ShowDetail = True
ActiveWorkbook.SaveAs Filename:="C:\test\7.csv", FileFormat:=xlCSV, _
CreateBackup:=False
ActiveSheet.Next.Select
Range("X7").Select
Selection.ShowDetail = True
ActiveWorkbook.SaveAs Filename:="C:\test\8.csv", FileFormat:=xlCSV, _
CreateBackup:=False
ActiveSheet.Next.Select
ActiveWindow.Close
End Sub

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
TRUE/FALSE STATEMENT Dave Excel Discussion (Misc queries) 4 September 1st 09 11:55 AM
Deleting Duplicate Rows In a Selection with a True Statement Josh heep Excel Programming 2 February 13th 08 07:37 PM
Two TRUE to one FALSE statement bluebird Excel Worksheet Functions 4 January 11th 07 04:07 PM
If then statement with two true conditions Don Guillett[_4_] Excel Programming 0 October 16th 04 12:01 AM
Run Macro on true statement Jack S. Excel Programming 2 August 10th 04 05:19 PM


All times are GMT +1. The time now is 10:01 PM.

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"