Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Identifying a Pivot Table

How can I tell in code, I the current tab contains a pivot table.

Actually, I need the code for Access, But if I can see the code in an Excel
Macro I can translate it to Access VBA. (Hopefully)

Thanks
--
Shell
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Identifying a Pivot Table

One way:

Option Explicit
Sub testme()

Dim wks As Worksheet

Set wks = ActiveSheet

If wks.PivotTables.Count 0 Then
MsgBox "yep"
Else
MsgBox "nope"
End If

End Sub



Shell wrote:

How can I tell in code, I the current tab contains a pivot table.

Actually, I need the code for Access, But if I can see the code in an Excel
Macro I can translate it to Access VBA. (Hopefully)

Thanks
--
Shell


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Identifying a Pivot Table

dim pvt as pivottable

for each pvt in activesheet.pivottables
msgbox pvt.name
next pvt
--
HTH...

Jim Thomlinson


"Shell" wrote:

How can I tell in code, I the current tab contains a pivot table.

Actually, I need the code for Access, But if I can see the code in an Excel
Macro I can translate it to Access VBA. (Hopefully)

Thanks
--
Shell

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Identifying a Pivot Table

I use this function in my pivot tools to see whether there is any
pivot table to work with.

Function getPivotTable() As PivotTable
Dim ch As ChartObject
On Error Resume Next

Set ch = ActiveChart
If Not ch Is Nothing Then
Set getPivotTable = ActiveChart.PivotLayout.PivotTable ' 1st
will see whether we have an active pivot chart
If Not getPivotTable Is Nothing Then Exit Function
End If

Set getPivotTable = ActiveCell.PivotTable ' 2nd will see whether
there is an active pivot table
If Not getPivotTable Is Nothing Then Exit Function

Set getPivotTable = ActiveSheet.PivotTables(1) ' lets see
whether there is at least one pivot table on the sheet
If Not getPivotTable Is Nothing Then Exit Function

If ActiveSheet.ChartObjects.Count 0 Then ' or an
embedded pivot chart
For Each ch In ActiveSheet.ChartObjects
If ch.Chart.HasPivotFields Then
Set getPivotTable = ch.Chart.PivotLayout.PivotTable
Exit For
Else
Set getPivotTable = Nothing
End If
Next ch
Else ' done our best to find the pivot
table that we can work with
Set getPivotTable = Nothing ' this should trigger an error
message in the caller now.
End If

End Function

' for testing this should work roughly
sub test()
dim pt as pivottable
set pt=getpivottable()
if pt is nothing then
msgbox "Goto sheet with a pivot table and try again!"
exit sub
end if
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
Identifying the row and column of a table value JHB Excel Discussion (Misc queries) 6 January 28th 09 10:17 PM
Identifying Source Data for Pivot Tables kleivakat Excel Discussion (Misc queries) 2 December 19th 07 03:54 PM
Identifying a cell/value in a table Ian Murdoch Excel Discussion (Misc queries) 5 August 1st 06 05:26 AM
Pivot Table - identifying datasource halemweg Excel Discussion (Misc queries) 1 July 1st 05 07:03 PM
Identifying Pivot Table's Field Juan Sanchez Excel Programming 2 October 5th 04 03:06 PM


All times are GMT +1. The time now is 03:13 PM.

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"