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:
If I can remove this can I just add an else after this
<strike></strike><strike></strike>
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
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>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 & "%"
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
Thanks
<strike></strike><strike></strike>