1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| Sub test()
Dim dernligne As Long
Dim j As Integer
Dim k As Integer
With Sheets("feuil1")
dernligne = .Range("A" & Rows.Count).End(xlUp).Row
For k = dernligne To 1 Step -1
If .Cells(k, 3).Value Like "X" Then
valrech = .Cells(k, 2).Value
c = WorksheetFunction.CountIf(Sheets("feuil2").Range("A:A"), valrech)
If c > 0 Then Rows(k + 1).Resize(c - 1).Insert
For j = 0 To c - 1
.Cells(k + j, 1).Value = .Cells(k, 1)
.Cells(k + j, 2).Value = .Cells(k, 2)
.Cells(k + j, 3).Value = .Cells(k, 3)
Next j
End If
Next k
End With
'******************remplir colonnes
Dim wSh1 As Worksheet, wSh2 As Worksheet
Dim derlig As Long
Dim MemeProduit As Range, kL2 As Long
Set wSh1 = ActiveWorkbook.Worksheets("feuil1")
Set wSh2 = ActiveWorkbook.Worksheets("Feuil2")
derlig = wSh1.Range("A" & Rows.Count).End(xlUp).Row
j = 0
kL2 = 1
For i = 2 To derlig
If wSh1.Cells(i, 3) Like "X" Then
Set MemeProduit = wSh2.Range("A" & kL2 & ":A" & derlig).Find(wSh1.Cells(i, 2), LookIn:=xlValues)
If MemeProduit Is Nothing Then
'--- le produit indiqué dans wSh1 n'est pas mentionné dans wSh2
Else
If MemeProduit <> 0 Then
kL2 = MemeProduit.Row
wSh1.Cells(i, 3) = wSh2.Cells(kL2, 2)
End If
End If
End If
Next i
End Sub |
Partager