Insérer des nouvelles lignes sans recopier les anciennes
Voici mon problème. J'ai une feuille excel à partir de laquelle je recopier ceretaines lignes sur une autre feuille à l'aide de la macro suivante:
Const NotesColumn As Integer = 16
Dim OptionCol(4) As Integer
Sub DupliquerINSPECTION()
OptionCol(1) = 9
Dim i As Integer
For i = 2 To UBound(OptionCol)
OptionCol(i) = OptionCol(i - 1) + 2
Next i
Dim dupliLine As Long
Dim InputLine As Long
dupliLine = Worksheets("Feuil2").Range("A" & Rows.Count).End(xlUp).Row + 1
InputLine = 2
While Worksheets("INSPECTION").Cells(InputLine, 3).Value <> ""
If Worksheets("INSPECTION").Cells(InputLine, 7).Value <> "" Then
Call AddLine(Worksheets("INSPECTION"), InputLine, Worksheets("Feuil2"), dupliLine)
End If
InputLine = InputLine + 1
Wend
Sheets("Feuil2").Activate
End Sub
Sub AddLine(wsSource As Worksheet, InputLine As Long, wsTarget As Worksheet, targetLine As Long)
Dim ColI As Integer
With wsTarget
For ColI = 1 To 4
.Cells(targetLine, ColI + 1).Value = wsSource.Cells(InputLine, 1 + ColI).Value
Next ColI
.Cells(targetLine, 5).Value = wsSource.Cells(InputLine, NotesColumn).Value
If .Cells(targetLine, 2).Value = "" Then .Cells(targetLine, 2).Value = .Cells(targetLine - 1, 2).Value
Call AddOptionsLines(wsSource, InputLine, wsTarget, targetLine)
End With
End Sub
Sub AddOptionsLines(wsSource As Worksheet, InputLine As Long, wsTarget As Worksheet, targetLine As Long)
Dim targetLineAtBegin As Long
targetLineAtBegin = targetLine
With wsTarget
.Range(.Cells(targetLine, 2), .Cells(targetLine, 5)).Copy
Dim i As Integer
For i = 1 To UBound(OptionCol)
If wsSource.Cells(InputLine, OptionCol(i)).Value <> "" Then
.Cells(targetLine, 2).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone
.Cells(targetLine, 6).Value = wsSource.Cells(InputLine, OptionCol(i) - 1).Value
targetLine = targetLine + 1
End If
Next i
If targetLine = targetLineAtBegin Then
targetLine = targetLine + 1
End If
End With
End Sub
Le seul petit problème est que si je veut rajouter des lignes dans ma première feuille en les recopiant dans ma deuxième feuille mes anciennes lignes se recopient. Comment faire pour copier seulement mes nouvelles lignes ?
Bonjour