Bonjour,
Avec un peu de retard, j'ai finalement opté pour une solution d'insertion de ligne et de redimensionnement du tableau pour palier à l'erreur. Effectivement je n'ai pas pour habitude de superposer les tableaux mais dans mon cas je n'ai pas le choix.
Néanmoins je me retrouve à présent face à un problème pour importer les données dans mon tableau ou du moins les données ne s'importent pas correctement.
Voici donc le code que j'ai créé, aucune erreur n'apparait mais l'import ne se fait pas dans les bonnes lignes de mon tableau de destination, voir même à l'extérieur du tableau. Après de nombreux essais, je n'arrive pas à trouver la solution... j'ai encore du pain sur la planche pour comprendre le fonctionnement des objets!
Constantes:
Global oFeuilleSource As Worksheet
Global oFeuilleDestination As Worksheet
Global oTableauDestination As ListObject
Global oTableauSource As ListObject
Extrait Macro principale:
For Each Ligne In oTableauSource.DataBodyRange.Rows
If oTableauSource.ListColumns("Je07 à produire GF").Range(Ligne.Row) = "x" And oTableauSource.ListColumns("Etat du document").Range(Ligne.Row) = "Prévu" Then
Set oLigneSource = oTableauSource.ListRows.Item(Ligne.Row)
PositionLigneSource = oLigneSource.Index
Set oTableauDestination = getTableau(oFeuilleDestination, "Données")
Insert_Ligne oTableauDestination
Condition_Import PositionLigneSource, oTableauDestination
End If
Next
Macro secondaires :
Sub Insert_Ligne(oTableauDestination As ListObject)
Dim DerLigneTableau As Integer
Dim j As Integer
If oTableauDestination.DataBodyRange Is Nothing Then
j = 1
Else: j = oTableauDestination.ListRows.Count
End If
DerLigneTableau = oTableauDestination.Range.Row + j
With oFeuilleDestination
.Rows(DerLigneTableau + 1).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
'Redimensionnement tableau
oTableauDestination.Resize
oTableauDestination.Range.Resize(oTableauDestination.Range.Rows.Count + 1, oTableauDestination.Range.Columns.Count)
End With
End Sub
Sub Condition_Import(PositionLigneSource As Long, oTableauDestination As ListObject)
Dim PositionLigneDestination As Long
PositionLigneDestination = oTableauDestination.ListColumns(1).Range.Find("", SearchDirection:=xlNext).Row
With oTableauDestination
.DataBodyRange(PositionLigneDestination, oTableauDestination.ListColumns("PORTEUR").Index) = oTableauSource.DataBodyRange(PositionLigneSource, oTableauSource.ListColumns("Porteur (rédaction)").Index).Value
.DataBodyRange(PositionLigneDestination, oTableauDestination.ListColumns("DOCUMENT").Index) = oTableauSource.DataBodyRange(PositionLigneSource, oTableauSource.ListColumns("Désignation du Document").Index)
End With
Set oLigneDestination = Nothing
End Sub