While cell is not empty

Solved
Sam2021 Posted messages 1 Status Membre -  
yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention   -
Bonjour

I cannot create a loop. Instead of ("AB2:AB11"), I would like to create a loop as long as the cell is not empty, filter, and paste into a new workbook.

 Sub filtreetclasseurOK() 'select the range to filter Range("A7").Select Range(Selection, Selection.End(xlDown)).Select Range(Selection, Selection.End(xlToRight)).Select Selection.AutoFilter 'filter based on year and direction For Each cell In Range("AB2:AB11") Worksheets("Travail RAR").Range("A$7").AutoFilter _ Field:=27, _ Criteria1:=cell.Value, _ VisibleDropDown:=True 'copy the filter to a new sheet ActiveSheet.AutoFilter.Range.Copy Workbooks.Add.Worksheets(1).Paste chemin = ThisWorkbook.Path ActiveWorkbook.SaveAs Filename:=chemin & "\" & cell.Value & ".xls" Workbooks(cell.Value & ".xls").Close Next cell End Sub


Thank you

Best regards
Sandie

2 réponses

yg_be Posted messages 23437 Registration date   Status Contributeur Last intervention   Ambassadeur 1 587
 
Hello,
not paying attention to what was in the loop:
set cell = Range("AB2") do while cell <> "" ' ... set cell=cell.offset(1) loop
0