Re,
Je ne pense pas que ta solution soit viable.
Pas beaucoup plus de précisions, mais...
Voir fichier modifié avec ce que j'ai compris.
J'ai mis des 'Stop' dans la procédure, pour que tu puisses comprendre la logique retenue ( et lis les commentaires ).
Dans l'éditeur VBE, faire F5 pour pou poursuivre son déroulement
Pour l'importation, on verra après, quand on aura résolu la demande initiale.
A te relire.
Cdlt
Option Explicit
Option Private Module
'http://forum.excel-pratique.com/excel/copier-20-des-lignes-non-vide-et-selon-un-prefixe-t54758.html
Public Sub Consolidation()
' declaration des variables
Dim ws As Worksheet
Dim lastRow As Long, lRow As Long, I As Long
Dim lo As ListObject
Dim strCode As String, strCritere1 As String, strCritere2 As String
' optimisation code
Application.ScreenUpdating = False
Application.Calculation = False
' initialisation objet
Set ws = Worksheets("Data")
With ws
.Range("F1:L1").EntireColumn.Delete
.[F4:L4] = Array("date arrive", "vol d'arrive", "date depart", "vol depart", "Code", "Critère1", "Critère2")
lastRow = .Cells(Rows.Count, 1).End(xlUp).Row
lRow = 5
' copie des donnes initiales suivant conditions pre-etablies
For I = 2 To lastRow
If .Cells(I, 1) = .Cells(I, 3) Then
If Right(.Cells(I, 2), 1) <> "F" And Right(.Cells(I, 2), 1) <> "P" Then
If Right(.Cells(I, 4), 1) <> "F" And Right(.Cells(I, 4), 1) <> "P" Then
.Range(.Cells(lRow, 6), .Cells(lRow, 9)) = _
.Range(.Cells(I, 1), .Cells(I, 4)).Value
lRow = lRow + 1
End If
End If
End If
Next I
Stop
' initialisation tableau final
Set lo = .ListObjects.Add(xlSrcRange, .Cells(4, 6).CurrentRegion, , xlYes)
With lo
.Name = "tblFinal"
.TableStyle = "TableStyleLight1"
End With
Stop
' tri tableau date/vol d'arrivee
With lo.Sort
With .SortFields
.Clear
.Add Key:=Range("tblFinal[date arrive]"), _
SortOn:=xlSortOnValues, Order:=xlAscending
.Add Key:=Range("tblfinal[vol d''arrive]"), _
SortOn:=xlSortOnValues, Order:=xlAscending
End With
.Header = xlYes
.Orientation = xlSortColumns
.Apply
End With
Stop
' Formules texte
' supprimer les caracteres numeriques
strCode = "=DeleteNum([@[vol d''arrive]])"
' compter le nombre d'occurences total des codes
strCritere1 = "=COUNTIFS([date arrive],[@[date arrive]],[Code],[@Code])"
' rang code
strCritere2 = "=COUNTIFS(R5C[-6]:RC[-6],RC[-6],R5C[-2]:RC[-2],RC[-2])"
' insertion Formules
.Cells(5, 10).Formula = strCode
.Cells(5, 11).Formula = strCritere1
.Cells(5, 12).Formula = strCritere2
Stop
' suppression formules code
Range("tblFinal[code]") = Range("tblFinal[code]").Value
Range("tblFinal[Critère1]") = Range("tblFinal[Critère1]").Value
Range("tblFinal[Critère2]") = Range("tblFinal[Critère2]").Value
Stop
' suppression des doublons codes suivant conditions pre-etablies
lastRow = .Cells(Rows.Count, 6).End(xlUp).Row
For I = lastRow To 5 Step -1
If .Cells(I, 11) > 4 And .Cells(I, 12) > 1 Then
.Range(.Cells(I, 6), .Cells(I, 12)).Delete
End If
Next I
Stop
' suppression colonnes inutiles (à adapter)
.Range("J1:L1").EntireColumn.Delete
.Range("F:I").Columns.AutoFit
End With
' reinitilisation calcul automatique
Application.Calculation = True
Set ws = Nothing: Set lo = Nothing
End Sub