I have the following code
Private Sub Worksheet_Change(ByVal Target As Range)
If InRange(ActiveSheet.ActiveCell, Range("M4:M1048576")) Then
MsgBox "ESTA EN EL RANGO DE M"
If (Not IsEmpty(ActiveCell.Offset(0, -1))) And (ActiveCell.Offset(0, -1).Value > 0) Then
Application.EnableEvents = False
If InStr(1, ActiveCell.Text, "EFECTIVO") > 0 Then
Call RestaEfectivo
ElseIf InStr(1, ActiveCell.Text, "BAC Débito") > 0 Then
Call RestaBAC
ElseIf InStr(1, ActiveCell.Text, "CITI Débito") > 0 Then
Call RestaCITI
ElseIf InStr(1, ActiveCell.Text, "BAC Crédito") > 0 Then
Call IncrementarCredito
End If
Application.EnableEvents = True
End If
End If
End Sub
which was set to a specific worksheet. However, I decided to ut it out from the worksheet and place it on ThisWorkbook. I'm very new to VBA so I have no idea what I need to change in the code so it executes on every worksheet, right now, the code won't execute at all.
Could anyone tell me what I need to change in my code so that it stays on ThisWorkbook and it executes on every sheet?
the event listener sub is not the same name in ThisWorkbook module.
just move the body of the code into this event listener in ThisWorkbook module:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
'Place the code here
End Sub
it will work.
cheers~
you can see what event listener are available using the drop down menu
pick one and VBA will automatically create the sub for you.
HTH.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.