Hello,
First of all, I am still new to VBA and more complex excel coding, so I'm learning by doing, searching forums and tutorials, stitching together bits and pieces of code I need. However, I ran into a dead end and would need help. Basically, what I'm trying to do: I have a project to sort documents based on certain criteria, and then decide to which department the document should be directed. Based on data in Column A, column F Decides if it goes after Quality, Logistics, Finances, or if it should be decided manually by someone. The command in the cell looks like this :
This works just fine. The other thing that I'm trying to do is, that every time the department is decided, email is generated to relevant person in that department. I figured that this should be based on the word in the column, and stitched together this code in VBA:
This code works, but only when I type the word "Quality" in the cell manually, hence missing the point of making it as automatic as possible.
I would like to ask if it's possible to make the macro read what the user sees, rather then what is physically in the cell.
Thank you very much for any help.
First of all, I am still new to VBA and more complex excel coding, so I'm learning by doing, searching forums and tutorials, stitching together bits and pieces of code I need. However, I ran into a dead end and would need help. Basically, what I'm trying to do: I have a project to sort documents based on certain criteria, and then decide to which department the document should be directed. Based on data in Column A, column F Decides if it goes after Quality, Logistics, Finances, or if it should be decided manually by someone. The command in the cell looks like this :
Excel Formula:
=IF(OR(A15="Late delivery",A15="Missing delivery",A15="Damaged packaging",A15="Wrong delivery note",A15="Wrong product"),"Logistics",IF(OR(A15="Damaged product",A15="Wrong description",A15="Different specifications"),"Quality",IF(OR(A15="Missing invoice",A15="Wrong price",A15="Late payment",A15="Wrong invoice"),"Finances","Manual")))
This works just fine. The other thing that I'm trying to do is, that every time the department is decided, email is generated to relevant person in that department. I figured that this should be based on the word in the column, and stitched together this code in VBA:
VBA Code:
Dim R As Range
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Target.Cells.Count > 1 Then Exit Sub
Set R = Intersect(Range("F2:F25"), Target)
If R Is Nothing Then Exit Sub
If InStr(1, (Range("f2:f25").Value), "Quality") > 0 Then
Call send_mail_outlook
End If
End Sub
Sub send_mail_outlook()
Dim x As Object
Dim y As Object
Dim z As String
Set x = CreateObject("Outlook.Application")
Set y = x.CreateItem(0)
z = "Hello!" & vbNewLine & vbNewLine & _
"This is a reminder that the database was updated and is waiting for your evaluation." & vbNewLine & _
""
On Error Resume Next
With y
.To = "XYZ@mail.com"
.cc = ""
.BCC = ""
.Subject = "Database update"
.Body = z
.Display
End With
On Error GoTo 0
Set y = Nothing
Set x = Nothing
End Sub
This code works, but only when I type the word "Quality" in the cell manually, hence missing the point of making it as automatic as possible.
I would like to ask if it's possible to make the macro read what the user sees, rather then what is physically in the cell.
Thank you very much for any help.