'Check Act
i = 2
Do While Cells(i, 1).Value <> ""
If Application.WorksheetFunction.VLookup(book1.Sheets("Hoja1").Cells(i, 1), book2.Sheets("Hoja3").Range("A:S"), 19, 0) = """" Then
Cells(i, 22) = "NO"
Else
Cells(i, 22) = "SI"
End If
i = i + 1
On Error Resume Next
Loop
'Preavis Compres
i = 2
x = ActiveSheet.UsedRange.Rows.Count
Do While Cells(i, 1).Value <> ""
For i = 2 To x
If Cells(i, 22) = "SI" Then
If Application.WorksheetFunction.VLookup(book1.Sheets("Hoja1").Cells(i, 1), book2.Sheets("Hoja3").Range("A:H"), 7, 0) = 2 And Application.WorksheetFunction.VLookup(book1.Sheets("Hoja1").Cells(i, 1), book2.Sheets("Hoja3").Range("A:H"), 8, 0) = 1 Then
Cells(i, 5) = "T+1"
ElseIf Application.WorksheetFunction.VLookup(book1.Sheets("Hoja1").Cells(i, 1), book2.Sheets("Hoja3").Range("A:H"), 7, 0) = 0 And Application.WorksheetFunction.VLookup(book1.Sheets("Hoja1").Cells(i, 1), book2.Sheets("Hoja3").Range("A:H"), 8, 0) = 0 Then
Cells(i, 5) = "T+0"
ElseIf Application.WorksheetFunction.VLookup(book1.Sheets("Hoja1").Cells(i, 1), book2.Sheets("Hoja3").Range("A:H"), 7, 0) = 1 And Application.WorksheetFunction.VLookup(book1.Sheets("Hoja1").Cells(i, 1), book2.Sheets("Hoja3").Range("A:H"), 8, 0) = 1 Then
Cells(i, 5) = "T-1"
ElseIf Application.WorksheetFunction.VLookup(book1.Sheets("Hoja1").Cells(i, 1), book2.Sheets("Hoja3").Range("A:H"), 7, 0) = 1 And Application.WorksheetFunction.VLookup(book1.Sheets("Hoja1").Cells(i, 1), book2.Sheets("Hoja3").Range("A:H"), 8, 0) = 2 Then
Cells(i, 5) = "T-2"
ElseIf Application.WorksheetFunction.VLookup(book1.Sheets("Hoja1").Cells(i, 1), book2.Sheets("Hoja3").Range("A:H"), 7, 0) = 1 And Application.WorksheetFunction.VLookup(book1.Sheets("Hoja1").Cells(i, 1), book2.Sheets("Hoja3").Range("A:H"), 8, 0) = 3 Then
Cells(i, 5) = "T-3"
End If
End If
Next i
i = i + 1
On Error Resume Next