lundi 23 juillet 2018

IF AND Statement in Excel VBA

I am trying to automate Outlook emails, and have the current code, but I need it to also have the condition that column "AF" is less than or equal to 7:

 'If there are unique values start the loop
If Rcount >= 2 Then
    For Rnum = 2 To Rcount

        'If the unique value is a mail address and if AF<= 7 create a mail 


 If Cws.Cells(Rnum, 1).Value Like "?*@?*.?*" And Cws.Cells(Rnum, 25) <= 7 Then
            'Filter the FilterRange on the FieldNum column
            FilterRange.AutoFilter Field:=FieldNum, _
                                   Criteria1:=Cws.Cells(Rnum, 1).Value
' and So on

The code will create an email when "And Cws.Cells(Rnum, 25) <= 7" is not included. It has a 25 because the email addresses technically start in row H(8), but the Field number begins at 8. I'm not sure if this an issue with the way I am calling the columns or the way it is written.

I have also tried:

'If the unique value is a mail address create a mail
        If Cws.Cells(Rnum, 1).Value Like "?*@?*.?*" And _
        LCase(Cells(cell.Row, "AF").Value) <= "7" Then

but this does not work either

Aucun commentaire:

Enregistrer un commentaire