• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Macro Should Execute Only On Tab

Hello,

I have a macro that executes very well if the user is on the Trend Analysis tab. Here is part of the code:
>>> use code - tags <<<
Code:
Sub Checkbox1_Click()
ActiveSheet.ChartObjcts("Chart 639").Activate
ActiveChart.Axes(xlValue).MinimumScale = Range ("Chart639')
End Sub
This code sets a minimum scale value for Chart 639 when a form control checkbox is clicked. The trouble is that this same checkbox is located on other tabs in the workbook, and they're all linked. It's used to include or exclude certain elements in the Total tabs, wherever such a rollup appears in the workbook. If I'm on the Total tab, which has the same checkbox, clicking it will generate an error--"the item with the specified name wasn't found." I think that means it's looking for Chart 639 and not finding it on the Total tab.

I only want this code to be executed when I'm on the Trend Analysis tab, and nowhere else. How can this be done?

Paul
 
Last edited by a moderator:
Maybe
Code:
Sub Checkbox1_Click()
If ActiveSheet.Name <> "Trend Analysis" Then Exit Sub
ActiveSheet.ChartObjcts("Chart 639").Activate
.............
 
Hello, activate first the correct worksheet​
or better with a single codeline just referencing the expected worksheet for each object …​
 
The trouble is that this same checkbox is located on other tabs in the workbook, and they're all linked.
It looks as if you've copied the checkbox (which you say is a Forms checkbox), or copied the sheet it's on, and so you've also copied the checkbox's assignment to the macro code.
You can remove that asignment by right-clicking the checkbox, choosing Assign Macro… and in the dialogue box that follows, delete what's in the Macro name: field and click OK.

1722353187273.png
 
Back
Top