Sending mail to different mail address based on cell value

  • Thread starter Thread starter Duncan
  • Start date Start date
D

Duncan

Hi

I need to add code to this below, basically, if a certain cell value = 00M
then send to one email address and if a certain cell value = 00C send to a
different email address.

An ideas?

Many thanks


Sub Email_Memo()
Range("B2:M34").Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
Range("A1").Select
ActiveWindow.DisplayGridlines = False
ActiveWindow.Zoom = 75
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
ActiveSheet.PageSetup.PrintArea = ""
With ActiveWindow
.DisplayHeadings = False
.DisplayHorizontalScrollBar = False
.DisplayVerticalScrollBar = False
.DisplayWorkbookTabs = False
End With
With ActiveSheet.PageSetup
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
.PrintErrors = xlPrintErrorsDisplayed
End With
ActiveWorkbook.SendMail ("(e-mail address removed)"),
("Memo From Store: ") & Sheets("Sheet1").Range("H4").Value
MsgBox "Your details have been sent", vbInformation, "PAYROLL MEMOS"
ActiveWindow.Close SaveChanges = True
Range("A1").Select

End Sub
 
see below ....

Duncan said:
Hi

I need to add code to this below, basically, if a certain cell value = 00M
then send to one email address and if a certain cell value = 00C send to a
different email address.

An ideas?

Many thanks


Sub Email_Memo()
Range("B2:M34").Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
Range("A1").Select
ActiveWindow.DisplayGridlines = False
ActiveWindow.Zoom = 75
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
ActiveSheet.PageSetup.PrintArea = ""
With ActiveWindow
.DisplayHeadings = False
.DisplayHorizontalScrollBar = False
.DisplayVerticalScrollBar = False
.DisplayWorkbookTabs = False
End With
With ActiveSheet.PageSetup
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
.PrintErrors = xlPrintErrorsDisplayed
End With

IF Worksheets("???").Range("???")="OOM" THEN
ActiveWorkbook.SendMail ("(e-mail address removed)"),
("Memo From Store: ") & Sheets("Sheet1").Range("H4").Value

ELSEIF Worksheets("???").Range("???")="OOC" THEN
ActiveWorkbook.SendMail ("(e-mail address removed)"),
("Memo From Store: ") & Sheets("Sheet1").Range("H4").Value

END IF
 
You could also set up string variable at the beginning of your procedure:

Dim strRecipient As String
If Range("Z1").Text = "00M" Then
strRecipient = "(e-mail address removed)"
ElseIf Range("Z1").Text = "00C" Then
strRecipient = "(e-mail address removed)"
End If

And then modify the send mail line:

ActiveWorkbook.SendMail strRecipient, _
("Memo From Store: ") & Sheets("Sheet1").Range("H4").Value
 
Back
Top