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
 

Some videos you may like

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
17,388
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Rewrite the sheet code to run from your command button, then delete the sheet code.
 

Philaz

New Member
Joined
Jan 9, 2014
Messages
22
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,815
Messages
5,598,259
Members
414,220
Latest member
Nations

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
Top