Execute worksheet_Change only on click event

Philaz

New Member
Joined
Jan 9, 2014
Messages
22
I have the following sheet code which is doing what I want it to do but I only want it to execute if I click commandbutton1. How do I do that?


Code:
Private Sub CommandButton1_Click()
'

End Sub
---------------------------------------------------
Private Sub CommandButton2_Click()
'
End Sub
-------------------------------------------------
Private Sub ToggleButton1_Click()
End Sub
-------------------------------------------------
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

End Sub
-------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)

'      "Other event code"
++++++++
'  Modify ROW ON DATA ENTRY TAB
    Dim rng1  As Range
    Dim cell  As Long
  If Not Intersect(Target, Range("d14:L5013")) Is Nothing Then
   On Error GoTo Oops
    If ActiveCell.row = Target.row Then
        MsgBox "same row"
        Application.EnableEvents = False
        ActiveSheet.Unprotect Password:="timewarp"
        With Range("d" & Target.row & ":M" & Target.row)
        .Cells.Locked = False
        Target.Font.Color = 500
        End With
    Else
        Range("d" & Target.row & ":M" & Target.row).Cells.Locked = True
         Target.Font.Color = 500
        MsgBox "row changed"
    End If
    Range("a20").Select
  Else
    MsgBox "not intersect"
   End If
'
outtahere:
    Application.EnableEvents = True
    ActiveSheet.Protect Password:="timewarp"
    MsgBox "exit"
    Exit Sub
Oops:
 MsgBox "Error"
 Resume outtahere
+++++++++++++++
'       "More event code here"

End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Rewrite the sheet code to run from your command button, then delete the sheet code.
 
Upvote 0
I am relying on the worksheet change target to identify the cell I just left so I don't think it will work to put the code in the commandbutton process. The target wouldn't be defined.
 
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,466
Members
449,086
Latest member
kwindels

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top