Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 137
Default Restrict Macro Availibility

Hi,

I am trying to restrict users to run a macro, only if ActiveCell is in
a specific range of a Pivot Table ...
Is there a simple way out ?

TIA
Carim

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Restrict Macro Availibility

Maybe something like this:

Option Explicit
Sub testme()
Dim PT As PivotTable
Set PT = Nothing
On Error Resume Next
Set PT = ActiveCell.PivotTable
On Error GoTo 0
If PT Is Nothing Then
MsgBox "hey, select a pt."
Else
MsgBox PT.Name
End If
End Sub


(Hi, Deb!)

Carim wrote:

Hi,

I am trying to restrict users to run a macro, only if ActiveCell is in
a specific range of a Pivot Table ...
Is there a simple way out ?

TIA
Carim


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 137
Default Restrict Macro Availibility

Hi Dave,

Thanks a lot for your input.
My ultimate objective is to have a "worksheet-selection-change" type of
solution ... i.e a command button which is only visible when user is
located inside the pivot table in range ("C2 : B90").

Your help would be greatly appreciated.

Cheers
Carim

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 137
Default Restrict Macro Availibility

Hi Dave,

Thanks a lot for your input.
My ultimate objective is to have a "worksheet-selection-change" type of
solution ... i.e a command button which is only visible when user is
located inside the pivot table in range ("C2 : B90").

Your help would be greatly appreciated.

Cheers
Carim

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Restrict Macro Availibility

Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim myShape As Shape
Dim PT As PivotTable

Set myShape = Me.Shapes("commandbutton1")
myShape.Visible = False

Set PT = Nothing
On Error Resume Next
Set PT = ActiveCell.PivotTable
On Error GoTo 0
If PT Is Nothing Then
'keep it hidden
Else
myShape.Visible = True
End If
End Sub

I put a commandbutton from the Control toolbox toolbar on the worksheet. I
named it commandbutton1 and it worked ok.

Carim wrote:

Hi Dave,

Thanks a lot for your input.
My ultimate objective is to have a "worksheet-selection-change" type of
solution ... i.e a command button which is only visible when user is
located inside the pivot table in range ("C2 : B90").

Your help would be greatly appreciated.

Cheers
Carim


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 137
Default Restrict Macro Availibility

Dave,

Many thanks ... it works beautifully...
I thought I had tried it this way, but it never worked ...
There will always be a hell of the difference between the pros ...
and the tiny amateurs ...
Cheers
Carim

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 137
Default Restrict Macro Availibility

Dave,

Sorry to be back again, but is there a way to push if further ... i.e
down to a couple of columns of the pivot table ...???

TIA

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Restrict Macro Availibility

Like if it's in the data range???

Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim myShape As Shape
Dim PT As PivotTable

Set myShape = Me.Shapes("commandbutton1")
myShape.Visible = False

Set PT = Nothing
On Error Resume Next
Set PT = ActiveCell.PivotTable
On Error GoTo 0
If PT Is Nothing Then
'keep it hidden
Else
If Intersect(Target.Cells(1), PT.DataBodyRange) Is Nothing Then
'keep it hidden
Else
myShape.Visible = True
End If
End If
End Sub



Carim wrote:

Dave,

Sorry to be back again, but is there a way to push if further ... i.e
down to a couple of columns of the pivot table ...???

TIA


--

Dave Peterson
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 137
Default Restrict Macro Availibility

Dave,

Thanks to your insight, I have discovered I had to dig into the pivot
table Object...
Next to DataBodyRange which includes all data, there is, for example :
..RowRange.Columns(1).Cells
to select data subsets ...

Thanks again for your precious help
Cheers
Carim

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Restrict Macro Availibility

There are a lot of ranges in those pivottables. Glad you found the one you
wanted.

Carim wrote:

Dave,

Thanks to your insight, I have discovered I had to dig into the pivot
table Object...
Next to DataBodyRange which includes all data, there is, for example :
.RowRange.Columns(1).Cells
to select data subsets ...

Thanks again for your precious help
Cheers
Carim


--

Dave Peterson
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
Restrict Users Restrict Users Excel Discussion (Misc queries) 1 January 12th 09 05:27 PM
i need availibility chart for employees shawna1219 Charts and Charting in Excel 2 January 2nd 09 11:18 PM
Macro to restrict printing to black and white dalymjl Excel Discussion (Misc queries) 2 October 19th 07 09:40 AM
RESTRICT PASTE Gator Girl Excel Worksheet Functions 0 August 29th 07 07:46 PM
Restrict Highlighting? David Excel Discussion (Misc queries) 4 July 29th 05 09:30 PM


All times are GMT +1. The time now is 07:07 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"