Cell.Target Value not working when the value comes from a formula

danielpt78

New Member
Joined
Mar 5, 2022
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hi all, hope you are well today, i have a little problem in my macro.
This macro is getting the value from a cell in F collumn and comparing it to the cell in G column. F is stock column (Which is chaning with a formula) and G is the minimum stock (Which is always a fixed value).

The macro only works when I input the value in F Column manually without using a formula (in this case is Column D (Inbound) - Column E (Outbound ))

Hope you understood my explanation and can help me! Thanks a lot!

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("F2:F5000")) Is Nothing Then
    If Cells(Target.Row, 6).Value = Cells(Target.Row, 7).Value Then
        Application.EnableEvents = False
        Cells(Target.Row, 10).Value = Cells(Target.Row, 10).Value + 1
            Dim xOutApp As Object
            Dim xOutMail As Object
            Dim xMailBody As String
            Set xOutApp = CreateObject("Outlook.Application")
            Set xOutMail = xOutApp.CreateItem(0)
            xMailBody = "Mail Text"
            On Error Resume Next
            With xOutMail
            .To = "Email Address"
            .CC = ""
            .BCC = ""
            .Subject = ""
            .Body = xMailBody
            .Display 'or use .Send
            End With
            On Error GoTo 0
            Set xOutMail = Nothing
            Set xOutApp = Nothing
        Application.EnableEvents = True
    ElseIf Cells(Target.Row, 6).Value < Cells(Target.Row, 7).Value Then
        Application.EnableEvents = False
        Cells(Target.Row, 11).Value = Cells(Target.Row, 11).Value + 1
        Application.EnableEvents = True
        End If
End If
End Sub
 
I think i explained wrong, the cell that matters the most for the stock is the column C in both sheets, A column is the input of the ID of the material and the value that goes to the sumif formula above is the one inputed in the C column
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
The Worksheet_Change event fires when you modify a cell. If the cell is the result of a formula, you are not really modifying the value of the cell, what is changing is the result of the formula, but the formula remains the same.
As I mentioned at the beginning. The cells you modify are the ones that trigger the event. If none of the cells are modified as they come from the result of other sheets then you need to use another approach.
 
Upvote 0
Solution
As I mentioned at the beginning. The cells you modify are the ones that trigger the event. If none of the cells are modified as they come from the result of other sheets then you need to use another approach.
Ok thanks a lot for the help! I will try to figure out another way to get to what i want. Have a nice day!
 
Upvote 0
If the cells that interfere with the result of cell F2 are in the Inbound Sheet table, then the event should go in the Inbound Sheet table, that is, you should check when a cell on that sheet is modified and check the result in F2 to send the mail.
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,707
Members
448,981
Latest member
recon11bucks

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