Stop excel from sending email when certain cells are blank

Keefer920

New Member
Joined
Jul 31, 2014
Messages
4
I have created a sheet with the following macro to email the page in the body of an email to a specified distribution list.

Sub Email()
'Working in Excel 2002-2013


Dim Sendrng As Range


On Error GoTo StopMacro


With Application
.ScreenUpdating = False
.EnableEvents = False
End With

'Note: if the selection is one cell it will send the whole worksheet
Set Sendrng = Worksheets("Sheet1").Range("A1:G20")

'Remember the activesheet
Set AWorksheet = ActiveSheet




'Create the mail and send it
With Sendrng


ActiveWorkbook.EnvelopeVisible = True
With .Parent.MailEnvelope


' Set the optional introduction field thats adds
' some header text to the email body.
.Introduction = "The PMC has received the following billing files. "



With .Item
'.To = "Anyone@anyplace.com"
.CC = ""
.BCC = ""
.Subject = "file arrival"
.Send

End With


End With
End With



StopMacro:
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
ActiveWorkbook.EnvelopeVisible = False


End Sub

This was working fine, except there has been errors by workers who are not confident in their ability to work in excel. A few critical cells have been left blank when sending the emails, leading to replies asking questions.

I have tried adding the following:

If Range("B2") = "" Then
i = MsgBox("Please put totals in all yellow cells", vbOKOnly + vbInformation, "Totals Sent!")
End If
If Range("D2") = "" Then
i = MsgBox("Please put totals in all yellow cells", vbOKOnly + vbInformation, "Totals Sent!")
End If
If Range("B3") = "" Then
i = MsgBox("Please put totals in all yellow cells", vbOKOnly + vbInformation, "Totals Sent!")
End If
If Range("D3") = "" Then
i = MsgBox("Please put totals in all yellow cells", vbOKOnly + vbInformation, "Totals Sent!")
End If
If Range("C5") = "" Then
i = MsgBox("Please put totals in all yellow cells", vbOKOnly + vbInformation, "Totals Sent!")
End If
If Range("C6") = "" Then
i = MsgBox("Please put totals in all yellow cells", vbOKOnly + vbInformation, "Totals Sent!")
End If
If Range("C7") = "" Then
i = MsgBox("Please put totals in all yellow cells", vbOKOnly + vbInformation, "Totals Sent!")
End If
If Range("C8") = "" Then
i = MsgBox("Please put totals in all yellow cells", vbOKOnly + vbInformation, "Totals Sent!")
End If
If Range("C9") = "" Then
i = MsgBox("Please put totals in all yellow cells", vbOKOnly + vbInformation, "Totals Sent!")
End If
If Range("C10") = "" Then
i = MsgBox("Please put totals in all yellow cells", vbOKOnly + vbInformation, "Totals Sent!")
End If
If Range("C11") = "" Then
i = MsgBox("Please put totals in all yellow cells", vbOKOnly + vbInformation, "Totals Sent!")
End If
If Range("C12") = "" Then
i = MsgBox("Please put totals in all yellow cells", vbOKOnly + vbInformation, "Totals Sent!")
End If
If Range("C13") = "" Then
i = MsgBox("Please put totals in all yellow cells", vbOKOnly + vbInformation, "Totals Sent!")
End If
If Range("B16") = "" Then
i = MsgBox("Please put totals in all yellow cells", vbOKOnly + vbInformation, "Totals Sent!")
End If

And it gives a pop up notifying that certain cells need to be filled in (Copied from a different sheet that referred to only 1 cell)

I am trying to find a way for the macro to end here if any cells are left blank, and send if all cells have an entry.

Any help would be greatly appreciated.
Thank you, Keith
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
if cell ="" then exit sub

Thank you. It looks like a simple fix (and it probably is) but I am unsure as to where to put your formula or exactly where in my original macro that I should place my "ifs"

Please excuse my ignorance, I was handed this task with no internal expert to offer me assistance.

Thanks again, Keith
 
Upvote 0
place it I am trying to find a way for the macro to end here if any cells are left blank, and send if all cells have an entry.

just after your last valid check and before the send routine proceeds,
 
Upvote 0

Forum statistics

Threads
1,215,766
Messages
6,126,754
Members
449,336
Latest member
p17tootie

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