Worksheet A has ranges of data that are collected from Worksheet B. Worksheet A has a macro that calculates if the data is above a value then calls an email module to email selected users.
When the data is manually input on Worksheet A the Macro works, however when data is pulled from Worksheet B it doesn't fire.
I'm not sure what I need to change in my VBA code.
Private Sub Worksheet_Change(ByVal Target As Range)
Call MailAlert(Target, "B5:M5", 4)
Call MailAlert(Target, "B8:M8", 7)
Call MailAlert(Target, "B11:M11", 6)
Call MailAlert(Target, "B14:M14", 2)
Call MailAlert(Target, "B17:M17", 4)
Call MailAlert(Target, "B20:M20", 1)
Call MailAlert(Target, "B23:M23", 3)
Call MailAlert(Target, "B26:M26", 1)
Call MailAlert(Target, "B29:M29", 5)
Call MailAlert(Target, "B32:M32", 1)
Call MailAlert(Target, "B35:M35", 7)
Call MailAlert(Target, "B38:M38", 20)
Call MailAlert(Target, "B41:M41", 0)
End Sub
Private Sub MailAlert(ByVal Target As Range, ByVal Address As String, ByVal Value As Integer)
If Target.Cells.Count > 1 Then Exit Sub
If Not Application.Intersect(Range(Address), Target) Is Nothing Then
If IsNumeric(Target.Value) And Target.Value > Value Then
Call Mail_small_Text_Outlook
End If
Application.EnableEvents = True
End If
End Sub
Run Macro When a Cell Changes (Method 1) Go to the VBA Editor (Alt + F11) and double-click the name of the spreadsheet that contains the cell that will change or just right-click the worksheet tab and click View Code.
VBA Pause is used to pause the code from executing it for a specified amount of time and to pause a code in VBA we use application. wait method. When we build large VBA projects after performing something, we may need to wait for some time to do other tasks.
Run or trigger macro if cell value equals specific text with VBA code. If you want to trigger the macro based on specific text in a cell, for instance, to run the macro1 if the text “Delete” is entered, and run macro2 if text “Insert” is typed.
To capture the changes by a formula you have to use the Worksheet_Calculate()
event. To understand how it works, let's take an example.
=Sheet2!A1+1
Now In a module paste this code
Public PrevVal As Variant
Paste this in the Sheet Code area
Private Sub Worksheet_Calculate()
If Range("A1").Value <> PrevVal Then
MsgBox "Value Changed"
PrevVal = Range("A1").Value
End If
End Sub
And lastly in the ThisWorkbook
Code area paste this code
Private Sub Workbook_Open()
PrevVal = Sheet1.Range("A1").Value
End Sub
Close and Save the workbook and reopen it. Now Make any change to the cell A1 of Sheet2
. You will notice that you will get the message box MsgBox "Value Changed"
SNAPSHOTS
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With