multiple worksheet changes

andysh

Board Regular
Joined
Nov 8, 2019
Messages
111
Hi

I have a worksheet change in a sheet but need to a second one. I know you can't have two changes in a sheet so is there a way I could combine the two changes below?

Private Sub worksheet_change(ByVal target As Range)
If target.Column <> 2 Ortarget.Cells.Count > 1 Then Exit Sub
Iftarget.Offset(0, -1) = "" Then
target.Offset(0,-1) = Now
target.Offset(0,8) = "USERNAME"
End If
End Sub


Private Sub worksheet_change(ByVal target As Range)

If Not Intersect(target,Range("E:E")) Is Nothing Then
Select Casetarget
Case"REJECT"
MsgBox"Please enter a reason for rejection"
End Select
End If
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Try this

Rich (BB code):
Private Sub worksheet_change(ByVal target As Range)
  Application.EnableEvents = False
  If target.Column = 2 And target.Cells.Count = 1 Then
    If target.Offset(0, -1) = "" Then
      target.Offset(0, -1) = Now
      target.Offset(0, 8) = "USERNAME"
    End If
  End If
  
  If Not Intersect(target, Range("E:E")) Is Nothing Then
    Select Case target
      Case "REJECT"
        MsgBox "Please enter a reason for rejection"
      End Select
  End If
  Application.EnableEvents = True
End Sub

BTW, when posting code please indent your code and use code tags to preserve that indentation - see my signature block below.
 
Last edited:
Upvote 0
That doesn't seem to work, neither of the subs are working

Apologies for the code, I'm having to mail the code to a laptop not on company network and it reformats
 
Upvote 0
That doesn't seem to work, neither of the subs are working
Perhaps your 'Events' have become disabled. Close right out of Excel then open it again & try again (with this sightly modified code replacing the previous suggestion).

Rich (BB code):
Private Sub worksheet_change(ByVal Target As Range)
  Application.EnableEvents = False
  If Target.Cells.Count = 1 Then
    If Target.Column = 2 Then
      If Target.Offset(0, -1) = "" Then
        Target.Offset(0, -1) = Now
        Target.Offset(0, 8) = "USERNAME"
      End If
    End If
    
    If Not Intersect(Target, Range("E:E")) Is Nothing Then
      Select Case Target
        Case "REJECT"
          MsgBox "Please enter a reason for rejection"
        End Select
    End If
  End If
  Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,115
Members
453,021
Latest member
Justyna P

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