If and statement

seasmith

New Member
Joined
Jul 6, 2011
Messages
44
I have this code that sends an email if the certain conditional formatting conditions are met the code is below

If x - Cells(3, 4) > 30 Then
Dim i As Long
i = 7
'code to see if a relief valve has to be retested'
Do While Range("A" & i) <> IsBlank
If Range("L" & i) = "" Then 'If the cell is blank an email is not sent'
ElseIf Range("L" & i) <= (Date - 365 * (3 * Range("N" & i))) - 182 Then

Address = Cells(i, 15) 'Sends the email to the email address in a certain row and column 15)
strbody = "Relief Valve number " & Cells(i, 1) & " at " & Cells(i, 2) & y & Cells(i, 3) & Cells(i, 4) & " needs to be tested" 'Concatenates the sentence with the relief valve number, location, compressor, and or subsystem'
Set OutApp = CreateObject("Outlook.Application") 'Opens outlook'
Set OutMail = OutApp.CreateItem(0) 'Create new message'

In the ElseIf part I would like to add an and where both parts of the ElseIf statement have to be true. The part after the and would be if the value in ("P" & i) = ChrW(&H25A1)
Im just not quite sure how to add this in to the code.
It would be something like
ElseIf Range("L" & i) <= (Date - 365 * (3 * Range("N" & i))) - 182 AND ("P" & i) = ChrW(&H25A1)
Then ....but I'm not quite sure if that is correct
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
In the ElseIf part I would like to add an and where both parts of the ElseIf statement have to be true. The part after the and would be if the value in ("P" & i) = ChrW(&H25A1)
Im just not quite sure how to add this in to the code.
It would be something like
ElseIf Range("L" & i) <= (Date - 365 * (3 * Range("N" & i))) - 182 AND Range("P" & i) = ChrW(&H25A1)
Then ....but I'm not quite sure if that is correct

you need to add what I show in the red and bold
 
Upvote 0
so what happens? Where is the macro failing? Try stepping through the macro, press F8 for each line of the macro and see where the process is and if it does the steps you expect. What line fails?
 
Upvote 0
So the code works it shows no error in the macro. But in column P I have symbols either a black box or a white box and the code is supposed to send an email to a specific person if the conditional formatting is met and there is a black box in column P. The code for the black box is ChrW(&H25A0), but for some reason when the code is run if there is a white box in column P it still sends an email. This is what my code looks like:

Private Sub CommandButton1_Click()
blackbox = ChrW(&H25A0)
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
x = Date
y = " "
If x - Cells(3, 4) > 30 Then
Dim i As Long
i = 7
'code to see if a relief valve has to be retested'
Do While Range("A" & i) <> IsBlank
If Range("L" & i) = "" Then 'If the cell is blank an email is not sent'
ElseIf Range("L" & i) <= (Date - 365 * (3 * Range("N" & i))) - 182 And Range("P" & i) = blackbox Then

Address = Cells(i, 15) 'Sends the email to the email address in a certain row and column 15)
strbody = "Relief Valve number " & Cells(i, 1) & " at " & Cells(i, 2) & y & Cells(i, 3) & Cells(i, 4) & " needs to be tested" 'Concatenates the sentence with the relief valve number, location, compressor, and or subsystem'
Set OutApp = CreateObject("Outlook.Application") 'Opens outlook'
Set OutMail = OutApp.CreateItem(0) 'Create new message'
 
Upvote 0

Forum statistics

Threads
1,217,007
Messages
6,133,993
Members
449,851
Latest member
laamiejbrown

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