Help with Loop

Status
Not open for further replies.

seasmith

New Member
Joined
Jul 6, 2011
Messages
44
<TABLE class=tborder id=post2795179 cellSpacing=0 cellPadding=6 width="100%" align=center border=0><TBODY><TR vAlign=top><TD class=alt1 id=td_post_2795179 style="BORDER-RIGHT: #ffffff 1px solid">I have this code (see below) that goes thru column L to see if the something is true or not and if it is true it sends an email to the email address in column 15. I am using my email address as a test to make sure it works and it is sending me 100's of emails. Is there anyway to have all the messages be sent in just one email?

For example the bold part is the body of the email that is to be sent is there anyway to get there where it goes:
Relief Valve number " & Cells(i, 1) & " at " & Cells(i, 2) & " needs to be tested
Relief Valve number " & Cells(i, 1) & " at " & Cells(i, 2) & " needs to be tested
Relief Valve number " & Cells(i, 1) & " at " & Cells(i, 2) & " needs to be tested and so on all in one email instead of being sent one by one


Private Sub CommandButton1_Click()
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
x = Date

If x - Cells(3, 4) > 30 Then
Dim i As Long

For i = 7 To 368
If Range("L" & i) <= (Date - 365 * (3 * Range("N" & i)) - 182) Then
Address = Cells(i, 15)
strbody = "Relief Valve number " & Cells(i, 1) & " at " & Cells(i, 2) & " needs to be tested"
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.To = Address
.CC = ""
.BCC = ""
.Subject = "Pressure Relief Valve" 'Subject line'
.Body = strbody
.Attachments.Add ActiveWorkbook.FullName
.Send 'Sends Email"

End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End If
Next i




Cells(3, 4) = x

End If
End Sub
<!-- / message -->
</TD></TR><TR><TD class=alt2 style="BORDER-RIGHT: #ffffff 1px solid; BORDER-TOP: #ffffff 0px solid; BORDER-LEFT: #ffffff 1px solid; BORDER-BOTTOM: #ffffff 1px solid">
user_online.gif
</TD><TD class=alt1 style="BORDER-RIGHT: #ffffff 1px solid; BORDER-TOP: #ffffff 0px solid; BORDER-LEFT: #ffffff 0px solid; BORDER-BOTTOM: #ffffff 1px solid" align=right><!-- controls --></TD></TR></TBODY></TABLE>
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Status
Not open for further replies.

Forum statistics

Threads
1,224,609
Messages
6,179,874
Members
452,949
Latest member
Dupuhini

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