ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to enable/disable a button. (https://www.excelbanter.com/excel-programming/299622-how-enable-disable-button.html)

Polly[_3_]

How to enable/disable a button.
 
Hi!

I have a problem in writing macro add in. I have created
a button specially for pivot table. When the selected
cell is in pivot table, this button will be enabled and
vice versa. I donno how to write this kind of macro. Can
somebody give me some hints to do?

Thanks!

Polly

Roger Whitehead[_4_]

How to enable/disable a button.
 
Hi Polly,

Dim rng As Range
On Error Resume Next
Set rng = ActiveCell.PivotTable.TableRange2
If rng Is Nothing Then
commandbutton1.Enabled = False
Else
commandbutton1.Enabled = True
End If
On Error GoTo 0



--
HTH
Roger
Shaftesbury (UK)



"Polly" wrote in message
...
Hi!

I have a problem in writing macro add in. I have created
a button specially for pivot table. When the selected
cell is in pivot table, this button will be enabled and
vice versa. I donno how to write this kind of macro. Can
somebody give me some hints to do?

Thanks!

Polly




Polly[_3_]

How to enable/disable a button.
 
Thanks! Roger.
I would like to know where the code should be put. I have
tried many places. Only when I put them in a worksheet,
it works. However, some people may not use my worksheet.
They may open or insert a new one.

Polly

-----Original Message-----
Hi Polly,

Dim rng As Range
On Error Resume Next
Set rng = ActiveCell.PivotTable.TableRange2
If rng Is Nothing Then
commandbutton1.Enabled = False
Else
commandbutton1.Enabled = True
End If
On Error GoTo 0



--
HTH
Roger
Shaftesbury (UK)



"Polly" wrote in

message
...
Hi!

I have a problem in writing macro add in. I have

created
a button specially for pivot table. When the selected
cell is in pivot table, this button will be enabled and
vice versa. I donno how to write this kind of macro.

Can
somebody give me some hints to do?

Thanks!

Polly



.



All times are GMT +1. The time now is 04:30 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com