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
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
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
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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