ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   active sheet (https://www.excelbanter.com/excel-programming/376443-active-sheet.html)

enyaw

active sheet
 
I have a custom toolbar and on that toolbar I have a button that runs a
macro. I have the macro running on the activesheet so it runs on whatever
sheet is open at the time. The problem is that I have a chart sheet. I want
to be able to stop the macro running if the chart sheet is the active sheet.
Can anyone help?

This is my code so far:

Sub macro1()
ActiveSheet.Select
UserForm1.Show
ActiveSheet.Unprotect
End Sub


DS

active sheet
 
Hi Enyaw,

Sub macro1()

ActiveSheet.Select
On Error Goto ChtFnd
Range("A1").Select
On Error Goto 0

UserForm1.Show
ActiveSheet.Unprotect
Exit Sub

ChtFnd:
End Sub

should do what you're looking for (in effect, if there is no cell "A1" to be
selected, as in a chart, it will go straight to the end of the sub, skipping
the call to the userform.)

HTH
DS


"enyaw" wrote:

I have a custom toolbar and on that toolbar I have a button that runs a
macro. I have the macro running on the activesheet so it runs on whatever
sheet is open at the time. The problem is that I have a chart sheet. I want
to be able to stop the macro running if the chart sheet is the active sheet.
Can anyone help?

This is my code so far:

Sub macro1()
ActiveSheet.Select
UserForm1.Show
ActiveSheet.Unprotect
End Sub


Bernie Deitrick

active sheet
 
Sub macro1A()
If ActiveSheet.Type = xlWorksheet Then
MsgBox "It's a worksheet"
UserForm1.Show
ActiveSheet.Unprotect
Else
MsgBox "It's not a worksheet"
End If
End Sub


--
HTH,
Bernie
MS Excel MVP


"enyaw" wrote in message
...
I have a custom toolbar and on that toolbar I have a button that runs a
macro. I have the macro running on the activesheet so it runs on whatever
sheet is open at the time. The problem is that I have a chart sheet. I want
to be able to stop the macro running if the chart sheet is the active sheet.
Can anyone help?

This is my code so far:

Sub macro1()
ActiveSheet.Select
UserForm1.Show
ActiveSheet.Unprotect
End Sub




enyaw

active sheet
 
Thanks DS.
Exactly what I was looking for.

"DS" wrote:

Hi Enyaw,

Sub macro1()

ActiveSheet.Select
On Error Goto ChtFnd
Range("A1").Select
On Error Goto 0

UserForm1.Show
ActiveSheet.Unprotect
Exit Sub

ChtFnd:
End Sub

should do what you're looking for (in effect, if there is no cell "A1" to be
selected, as in a chart, it will go straight to the end of the sub, skipping
the call to the userform.)

HTH
DS


"enyaw" wrote:

I have a custom toolbar and on that toolbar I have a button that runs a
macro. I have the macro running on the activesheet so it runs on whatever
sheet is open at the time. The problem is that I have a chart sheet. I want
to be able to stop the macro running if the chart sheet is the active sheet.
Can anyone help?

This is my code so far:

Sub macro1()
ActiveSheet.Select
UserForm1.Show
ActiveSheet.Unprotect
End Sub



All times are GMT +1. The time now is 06:07 PM.

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