I am pulling emails from Outlook into Excel with VBA, comparing the subject line of the email with a range of cells on another sheet. I am using a For Each loop to achieve this but it seems as though when my if condition is met, it keeps going so it doesn't post the result that I want. It seems to loop through all of the cells in the range I have defined but then even when it meets my if condition, it keeps going and ends up being blank.
Here I am defining my ranges:
Dim rRng As Range, cel As Range
Set rRng = Sheet2.Range("A2:A1218")
Here is my For Each loop:
For Each cel In rRng.Cells
If InStr(1, Folder.Items.Item(iRow).Subject, cel.Text) > 0 Then
ThisWorkbook.Sheets(1).Cells(oRow, 3) = cel.Value
End If
Next cel
Is there an even better approach?
Aucun commentaire:
Enregistrer un commentaire