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
| Sub Extract_data_base()
Dim ref As Integer
Dim cell_ref As Range
Dim rowmax As Integer
Dim cell_sc As Range
Dim off1 As Integer
Dim off2 As Integer
Dim str As String
Dim table() As String
ref = InputBox("Référence recherchée ?", "Référence", 0)
With Worksheets("Data")
Set cell_ref = .Columns(2).Find(ref, LookIn:=xlFormulas, lookat:=xlWhole)
If cell_ref Is Nothing Then
MsgBox "La référence n'a pas été trouvée"
Exit Sub
End If
rowmax = 0
For i = 0 To 2
test = Worksheets("Export").Columns(1 + (i * 4)).Find("*", , , , xlByColumns, xlPrevious).Offset(1, 0).Row
If Worksheets("Export").Columns(1 + (i * 4)).Find("*", , , , xlByColumns, xlPrevious).Offset(1, 0).Row > rowmax Then
rowmax = Worksheets("Export").Columns(1 + (i * 4)).Find("*", , , , xlByColumns, xlPrevious).Offset(1, 0).Row
End If
Next i
Set cell_des = Worksheets("Export").Cells(rowmax, 1)
For i = 0 To 3
cell_des.Offset(0, i) = cell_ref.Offset(0, i - 1)
Next i
Set cell_sc = .Columns(4).Find(ref, LookIn:=xlFormulas, lookat:=xlWhole)
If Not cell_sc Is Nothing Then
For i = 0 To 3
cell_des.Offset(0, i + 4) = cell_sc.Offset(0, i - 3)
Next i
ReDim table(1 To 1)
off1 = 0
off2 = 0
If cell_ref.Offset(0, 2) <> "" Then
If InStr(cell_ref.Offset(0, 2), ",") Then
off1 = InStr(cell_ref.Offset(0, 2), ",")
table(1) = Left(cell_ref.Offset(0, 2), off1 - 1)
For i = 2 To 100
If InStr(off1 + 1, cell_ref.Offset(0, 2), ",") Then
off2 = InStr(off1 + 1, cell_ref.Offset(0, 2), ",")
ReDim Preserve table(1 To i)
table(i) = Mid(cell_ref.Offset(0, 2), off1 + 2, off2 - off1 - 2)
off1 = off2
Else
ReDim Preserve table(1 To i)
table(i) = Right(cell_ref.Offset(0, 2), Len(cell_ref.Offset(0, 2)) - off1 - 1)
Exit For
End If
Next i
Else
table(1) = cell_ref.Offset(0, 2)
End If
End If
' strMessage = ""
' For boucle = 1 To UBound(table)
' strMessage = strMessage & table(boucle) & vbLf
' Next boucle
'
' MsgBox strMessage
For i = 0 To UBound(table) - 1
Set cell_sc = .Columns(2).Find(table(i + 1), LookIn:=xlFormulas, lookat:=xlWhole)
For j = 0 To 3
cell_des.Offset(i, j + 8) = cell_sc.Offset(0, j - 1)
Next j
Next i
End If
End With
End Sub |
Partager