Reputation: 2412
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:
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
Upvotes: 0
Views: 1225
Reputation: 3248
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
Upvotes: 2