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
| Sub Recherche()
'Déclaration des variables
Dim oRng As Range
Dim i As Integer, n As Integer
Dim oProd As Range, oCell As Range
Dim oTable() As String
'Avec Feuil5 (feuille de données)
With Worksheets("Panier")
'On se place sur B9
Set oRng = .Range("B9")
'On parcours de A1 à la dernière ligne non-vide
For i = 0 To .Cells(.Rows.Count, 1).End(xlUp).Row - 1
'Si on trouve "Tablette" ou "Produits" (on peut enlever le LCase si souhaité)
'If LCase(oRng.Offset(i, 0)) = "Tablette" Or LCase(oRng.Offset(i, 0)) = "Produits" Then
If oRng.Offset(i, 0) = "Tablette" Or oRng.Offset(i, 0) = "Produits" Then
'On vérifie qu'on a des éléments à sa droite
If .Cells(oRng.Offset(i, 1).Row, .Columns.Count).End(xlToLeft).Column >= oRng.Offset(i, 1).Column Then
'Si oui, on récupère la range des valeurs
Set oProd = Range(oRng.Offset(i, 1), .Cells(oRng.Offset(i, 1).Row, .Columns.Count).End(xlToLeft))
'qu'on parcours.
For Each oCell In oProd
'Si on trouve quelque chose
If oCell <> "" Then
n = n + 1
'on sauvegarde les éléments.
ReDim Preserve oTable(1 To 3, 1 To n)
oTable(1, n) = oCell
oTable(2, n) = oCell.Offset(1, 0)
oTable(3, n) = oCell.DisplayFormat.Interior.Color
'Debug.Print oRng.Offset(i, 0) & " - " & oTable(1, n) & " - " & oTable(2, n) & " / " & oCell.Offset(1, 0).AddressLocal & " - " & oTable(3, n)
End If
Next oCell
End If
End If
Next i
End With
'Avec Feuil6 (feuille de résultats)
With Worksheets("Resultats")
'On se place après la dernière cellule non-vide de la colonne 1
Set oRng = .Cells(.Rows.Count, 2).End(xlUp)
'et on y écrit les résultats.
For i = LBound(oTable, 2) To UBound(oTable, 2)
oRng.Offset(i, 0) = oTable(1, i)
'On ne déplace ici plus de 1 mais de 3 colonnes l'écriture des résultats.
oRng.Offset(i, 3) = oTable(2, i)
Next i
End With
End Sub |
Partager