0

I have Userform with buttons that are connected to codes. Why buttons keeps being pressed after code has been completed? Is there any way to release them?

Button looks like this after clicking on it:

enter image description here

Button code:

Private Sub ToggleButton2_Click() ThisWorkbook.Worksheets("Price calculation").Activate Application.ScreenUpdating = False ThisWorkbook.Sheets("Price calculation").Unprotect Password:="123" Range("1867:1979").EntireRow.Hidden = False ActiveSheet.Shapes("Rectangle: Rounded Corners 76").Visible = False ActiveSheet.Shapes("Rectangle: Rounded Corners 244").Visible = True ActiveWindow.ScrollRow = 1867 ThisWorkbook.Sheets("Price calculation").Protect Password:="123" Application.ScreenUpdating = True End Sub 
1

1 Answer 1

2

You're using a toggle button. These toggle, unsurprisingly. I reckon you are looking to use a CommandButton instead.

In the toolbox browse for the CommandButton control Replace the ToggleButton with the newly added CommandButton. Then, edit the code for your togglebutton and replace it with:

Private Sub CommandButton1_Click() Application.ScreenUpdating = False With ThisWorkbook.Sheets("Price calculation") .Activate .Unprotect Password:="123" .Range("1867:1979").EntireRow.Hidden = False .Shapes("Rectangle: Rounded Corners 76").Visible = False .Shapes("Rectangle: Rounded Corners 244").Visible = True ActiveWindow.ScrollRow = 1867 'Is this necessary? It scrolls to a specific hard-coded row .Protect Password:="123" End With Application.ScreenUpdating = True End Sub 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.