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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
Option Explicit
Dim tablo() As String
Dim code1() As String
Dim code2() As String
Dim i As Byte
Sub travdem()
Dim cellule As Range
Dim nomfeuille1 As String
Dim lig As Long
' pour boucler sur la colonne 1
nomfeuille1 = "Feuil1"
With Sheets(nomfeuille1)
For Each cellule In .UsedRange.Columns(1).Cells
cellule.Offset(0, 1) = cellule & " "
If cellule <> "" Then
tablo() = Split(cellule, " ")
Call decomp(1)
If code1(1) <> "" Then
lig = rechercheligne(nomfeuille1, "a", code1(1), cellule.Row + 1)
If lig > 0 Then
cellule.Offset(0, 1) = cellule.Offset(0, 1) & "Article" & " " & code1(1)
End If
End If
End If
Next cellule
End With
End Sub
'----------------------------------------------
'
Private Function rechercheligne(£feuille As String, £colonne As String, £dataf As String, £depart As Long)
Dim £dataf1 As String
Dim £if1 As Integer
Dim £if2 As Long, £dl1 As Long
Dim £cell As Range
With Sheets(£feuille)
£dl1 = .Range(£colonne & Rows.Count).End(xlUp).Row
If £depart <= £dl1 Then
For Each £cell In .Range(£colonne & £depart & ":" & £colonne & £dl1)
tablo() = Split(£cell, " ")
Call decomp(2)
If code2(0) = £dataf Then
rechercheligne = £cell.Row
Exit Function
End If
Next £cell
rechercheligne = 0
End If
End With
End Function
' décomposition du texte pour mettre en évidence les codes
' val1 sert simplement à indiquer la variable pour la réponse
Private Sub decomp(val1 As Byte)
Dim j As Byte
Dim data1 As String
j = 0
i = LBound(tablo)
data1 = ""
Do
If tablo(i) = "Article" Then
If data1 = "" Then
data1 = tablo(i + 1)
Else
data1 = data1 & "/" & tablo(i + 1)
End If
End If
i = i + 1
If i > UBound(tablo) Then Exit Do
Loop
If val1 = 1 Then code1() = Split(data1, "/")
If val1 = 2 Then code2() = Split(data1, "/")
End Sub |
Partager