Calling new Subs

Saeva

New Member
Joined
Oct 6, 2022
Messages
11
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hello,
So, with help of kind people here I was able to make most of my project work, but have hit the hopefully last bump. Basically, I have a worksheet that based on condition decides whether the issue should go after Quality, Logistics or Finances, and then generates an email to be just sent to the responsible person. But, whenever I fill in new cell, all the previous cells are triggered, and therefore if there were previously three sorted problems, after filling new one, four emails are open. Is there a way, how to open outlook just for the new cell?
Here is what the code that calls the emails looks like:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
                    Dim LastRow As Long
                Dim i As Long
            LastRow = Range("B" & Rows.Count).End(xlUp).Row
        For i = 2 To LastRow
        If Range("B" & i).Value = "Late delivery" Or Range("B" & i).Value = "Missing delivery" Or Range("B" & i).Value = "Damaged packaging" Or Range("B" & i).Value = "Wrong delivery note" Or Range("B" & i).Value = "Wrong product" Then
    Range("D" & i).Value = "Logistics"
        End If
    If Range("B" & i).Value = "Damaged product" Or Range("B" & i).Value = "Wrong description" Or Range("B" & i).Value = "Different specifications" Then
    Range("D" & i).Value = "Quality"
        End If
    If Range("B" & i).Value = "Missing invoice" Or Range("B" & i).Value = "Wrong price" Or Range("B" & i).Value = "Late payment" Or Range("B" & i).Value = "Wrong invoice" Then
    Range("D" & i).Value = "Finances"
        End If
    If Range("D" & i).Value = "Quality" Then
    Call send_mail_outlook_Qvl
        End If
    If Range("D" & i).Value = "Logistics" Then
    Call send_mail_outlook_Log
        End If
    If Range("D" & i).Value = "Finances" Then
    Call send_mail_outlook_Fin
        End If
    Next i
Application.EnableEvents = True
    
End Sub

Thank you so much for your help
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
If you only want the code triggered by new data, you should only be monitoring the Target (and perhaps its row) not looping from row 2 to the bottom.
 
Upvote 0
Solution
If you only want the code triggered by new data, you should only be monitoring the Target (and perhaps its row) not looping from row 2 to the bottom.
Hello, yes, you were right. I am still new to this, and so I still don't understand many processes. I changed the code to monitor target instead and it works now perfectly.
 
Upvote 0

Forum statistics

Threads
1,223,879
Messages
6,175,148
Members
452,615
Latest member
bogeys2birdies

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