Good afternoon everyone,
i have a workbook with 13 worksheets ( 1 per each month and one recap). I am trying to look for the value of "No fiche chantier" - column D) in every worksheets (
except "impayes" - index 13), then if it's found in the worksheet x and that the column "o" is NOT empty, then delete relevant row from the worksheet "impayes".
Ex: 1. in the worksheet impayes row nr 5, take the value of column D = 18332
2. look for "18332" in all worksheets from "janvier" to "dec" (but NOT in "impayes")
3. if found in worksheet (in this example, "18332" does not exist in january, so jump to February, then found it), and in this worksheet the relevant row, column "o" is not empty
4 if 3 is true then delete relevant row from "impayes
Basically "impayes" repeats all the rows of all the other worksheets, but i want to keep only the row where the column O is empty.
Here is my code which is not working, it look first in "impayes" instead of excluding it:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Long, irow As Long, r As Range, ws As Worksheet, sfilter As String
'pour chaque ligne de la feuille ("impayes") a partir de la ligne 5 jusqu'a la derniere ligne ou la colonne B est vide
For i = 5 To Range("B" & Rows.Count).End(xlUp).Row
' sfilter = No fiche chantier (colonne D)
sfilter = Cells(i, "d")
For Each ws In ThisWorkbook.Worksheets
If ws.Index <> 13 Then
ws.Activate
irow = ws.Cells.Find(What:=sfilter, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Row
If Cells(irow, "o") <> 0 Then
Rows(i).EntireRow.Delete
End If
End If
Next ws
Next i
End Sub