combine worksheet_change event ?

desmond_

Board Regular
Joined
Jan 4, 2017
Messages
59
Dear experts,

i have two separate worksheet_change events which i want to use on the same sheet.

it seems per sheet only worksheet_change event can work,
so to overcome this issue i have to somehow combine them
any suggestions ?

the 1st

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   
   Dim Fnd As Range
   If Target.CountLarge > 1 Then Exit Sub
   If Not Target.Column = 3 Then Exit Sub
    Application.EnableEvents = False
   Set Fnd = Rows(1).Find(Target.Value, , xlValues, xlWhole, , , False, , False)
   If Not Fnd Is Nothing Then Target.Offset(, Fnd.Column - 3) = "x"
Application.EnableEvents = True
End Sub

and this is the 2nd


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo msg
Dim KeyCells As Range
Set KeyCells = Range("H18:BO205")
    If Not Application.Intersect(KeyCells, Range(Target.Address)) _
           Is Nothing Then
       If Target.Value = "x" Then


        Cells(Target.Row, Target.Column + 1).Value = 2
        Cells(Target.Row, Target.Column - 1).Value = 2.5
              
       End If
    End If


LetsContinue:
Application.EnableEvents = True
Exit Sub


msg:
MsgBox "insert is out of range"
Resume LetsContinue

thanks a lot !
Regards Desmond
 

Some videos you may like

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

desmond_

Board Regular
Joined
Jan 4, 2017
Messages
59
solved it -

Code:
Private Sub Worksheet_Change(ByVal Target As Range)   On Error GoTo msg
   Dim Fnd As Range
   Dim KeyCells As Range
   
   Set KeyCells = Range("D3:AY254")
        If Not Application.Intersect(KeyCells, Range(Target.Address)) _
        Is Nothing Then


        If Target.Value = "x" Then


        Cells(Target.Row, Target.Column + 1).Value = 2
        Cells(Target.Row, Target.Column - 1).Value = 2.5


       
       End If
    End If
    
   If Target.CountLarge > 1 Then Exit Sub
   If Not Target.Column = 3 Then Exit Sub
    Application.EnableEvents = False
   Set Fnd = Rows(1).Find(Target.Value, , xlValues, xlWhole, , , False, , False)
   If Not Fnd Is Nothing Then Target.Offset(, Fnd.Column - 3) = "x"
Application.EnableEvents = True


LetsContinue:
Application.EnableEvents = True
Exit Sub


msg:
MsgBox "insert is out of range"
Resume LetsContinue


End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,123,331
Messages
5,601,002
Members
414,419
Latest member
JRDunya

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