I find some difficulties when I try to compare values of two different Workbooks. The code has to delete the rows that do not follow the if condition, that is, if the value from the workbook "Nuevo hoja de cálculo" is between an interval of values from another workbook called "Formato CO-08a", it continues calculating a few variables (m,y_n, y) and if the value does accomplish the second if condition, then the row is deleted.
I have also tried to do it working with sheets from the same workbook, copying in the Workbook "Nuevo hoja de calculo" the sheet from the workbook "Formato CO-08a". But it still doesn't work, as the program doesn't achieve to read the values from this copied sheet. The example I wrote below works with sheets from the same workbook, but my goal is to work with 2 different workbooks.
For i = 1 To Sheets("Seleccion_ECs").listaopciones.ListCount
Line1:
For Z = 0 To 7
Debug.Print Z
If (Sheets("Seleccion_ECs").Cells(i + 1, E).Value >= ThisWorkbook.Sheets("Requisitos Contenedor + ATI").Cells(40 + Z, 4).Value) And (Sheets("Seleccion_ECs").Cells(i + 1, E).Value <= ThisWorkbook.Sheets("Requisitos Contenedor + ATI").Cells(41 + Z, 4).Value) Then
m = (ThisWorkbook.Sheets("Requisitos Contenedor + ATI").Cells(41 + Z, 2).Value - ThisWorkbook.Sheets("Requisitos Contenedor + ATI").Cells(40 + Z, 2).Value) / (ThisWorkbook.Sheets("Requisitos Contenedor + ATI").Cells(41 + Z, 4).Value - ThisWorkbook.Sheets("Requisitos Contenedor + ATI").Cells(40 + Z, 4).Value)
y = m * (Sheets("Seleccion_ECs").Cells(i + 1, E).Value - Sheets("Requisitos Contenedor").Cells(40 + Z, 2).Value) + Sheets("Requisitos Contenedor").Cells(40 + Z, 4).Value
y_n = Sheets("Seleccion_ECs").Cells(i + 1, Q).Value
Debug.Print ("Se ha encontrado un intervalo")
If y_n > 1.02 * y Then 'Si se sale en un 2 por ciento de la zona aceptada, se elimina la fila.
Worksheets("Seleccion_ECs").Rows(i + 1).Delete
GoTo Line1
Else:
i = i + 1 'Preguntar si vale esto teniendo el for i=0
GoTo Line1
End If
End If
Next Z
Next i
Thank you in advance