send email when changes are made to a worksheet

P

Pam M

I have a spreadsheet that shows sales committments as Firm or Pending. The
spreadsheet is used by several people who can change the status of a
committment at any time. I have a count field that counts the number of Firm
Committments, so when a committment changes from Pending to Firm, the counter
obviously changes. I would like to send an standard email automatically to
recipients each time the counter changes. I looked at Ron de Bruins example
where the cell value is > 200. the macro looks like it will work but I would
need help in adapting the change event where the target cell contains a
formula.
 
P

Pam M

Hi Ron--thanks so much for responding. Yes, I can see the 2nd event is for a
formula, but I'm not sure what to replace the line If Range("a1".Value>200
Then YourMacroName with. I want it the email sent every time someone changes
a status to firm, but only once since once its firm its done. I thought I'd
use a counter cell as my change event, but maybe I don't need it. The
formula in this cell is =COUNTIF(G3:G13,"FIRM"). I want an email sent only
once each time a row's status is changed to firm. The email will simply say
"please check sales sheet for recent status changes". Am I making this too
complicated?
 
P

Pam M

yes, they do. So I should then be able to use the manual example and skip
the counter cell, correct? With this, how does vb know to execute the send
the email only once? In other words, once a row is changed to FIRM it will
never need the email sent again.
 
R

Ron de Bruin

Hi Pam

Use this then, no need for the formula cell.

Be sure that the macro name = YourMacroName

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Range("G3:G13"), Target) Is Nothing Then
If LCase(Target.Value) = "firm" Then
Call YourMacroName
End If
End If
End Sub


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm
 
P

Pam M

Ron--works beautifully! Just a two quick questions...
1) How do I string multiple email addresses
2) Can I reference the row that caused the change in the email? If not, no
big deal. Just thought it would be nice.
 
R

Ron de Bruin

Try this Pam

It wil use the value in H as name rng.Offset(0, 1).Value and tell you which cell is changed
You can use any cell in the row in your text this way

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Application.Intersect(Range("G3:G13"), Target) Is Nothing Then
If LCase(Target.Value) = "firm" Then
Call Mail_with_outlook(Target)
End If
End If
End Sub

Copy the macro in a normal module
It show the mail for testing, change display to send if you want to send it directly

Sub Mail_with_outlook(rng As Range)
Dim OutApp As Object
Dim OutMail As Object
Dim strto As String, strcc As String, strbcc As String
Dim strsub As String, strbody As String

Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)

strto = "(e-mail address removed);[email protected]"
strcc = ""
strbcc = ""
strsub = "please check sales sheet for recent status changes"
strbody = "Hi " & rng.Offset(0, 1).Value & vbNewLine & vbNewLine & _
rng.Address & " is changed"

With OutMail
.To = strto
.CC = strcc
.BCC = strbcc
.Subject = strsub
.Body = strbody
.Display 'Or .Send
End With

Set OutMail = Nothing
Set OutApp = Nothing
End Sub


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm
 
P

Pam M

Ron, this is so slick. I was able to adapt this with the offset to include
the project name and number as well. You're the best. Thank you so much
for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top