Outlook Query

heffo500

New Member
Joined
Sep 28, 2016
Messages
44
Hi

I have the below code that sends an email if tow conditions are met.

I have two questions:

Sub email()
Dim i As Long, lr As Long, scdata As String, myolapp As Object, myitem As Object
lr = Range("A" & Rows.Count).End(xlUp).Row
scdata = ""
For i = 19 To lr Step 1
If Cells(i, 21) <> 0 And Cells(i, 21) <= -5 Then
If scdata = "" Then
scdata = Rows(i).Range("A1").Value & " " & Rows(i).Range("B1").Value & " " & Rows(i).Range("M1").Value & " " & Rows(i).Range("U1").Value & "%"
Else
scdata = scdata & Chr(13) & Rows(i).Range("A1").Value & " " & Rows(i).Range("B1").Value & " " & Rows(i).Range("M1").Value & " " & Rows(i).Range("U1").Value & "%"
End If
End If
Next
Set myolapp = CreateObject("Outlook.Application")
Set myitem = myolapp.CreateItem(olMailItem)
With myitem
.To = InputBox("Please confirm email address", , "email")
.CC = "email"
.Subject = "Investiagte Breach"
.Body = "Hi," & Chr(13) & Chr(13) & "Please see the Breach" & Chr(13) & Chr(13) & scdata & Chr(13) & Chr(13) & ""


.Send
End With
End Sub

What is the if function in place for below in bold:

scdata = ""
For i = 19 To lr Step 1
If Cells(i, 21) <> 0 And Cells(i, 21) <= -5 Then
If scdata = "" Then
scdata = Rows(i).Range("A1").Value & " " & Rows(i).Range("B1").Value & " " & Rows(i).Range("M1").Value & " " & Rows(i).Range("U1").Value & "%"
Else
scdata = scdata & Chr(13) & Rows(i).Range("A1").Value & " " & Rows(i).Range("B1").Value & " " & Rows(i).Range("M1").Value & " " & Rows(i).Range("U1").Value & "%"
<strike></strike>


If I can remove this can I just add an else after this
If Cells(i, 21) <> 0 And Cells(i, 21) <= -5 Then to send a different if the conditions are not met.

Thanks

<strike></strike><strike></strike>
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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