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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
| Sub Macro1()
'Declaration des variables
Dim Tab_asin(), tab_tmp(), tab_domo(), tab_market(), tab_tmp_market()
Dim sku, Asin, market, vendeur, prix, fba, Date_file, note
Dim Lastlig
Dim l
Dim p
Dim q
Dim domo
Dim r1
Dim r2
Application.ScreenUpdating = False
'Entetes feuille 3
With Worksheets("Feuil3")
.Cells(1, 1) = "SKU"
.Cells(1, 2) = "ASIN"
.Cells(1, 3) = "Marketplace"
.Cells(1, 4) = "Nom_vendeur"
.Cells(1, 5) = "Prix"
.Cells(1, 6) = "FBA"
.Cells(1, 7) = "Date"
.Cells(1, 8) = "Note_du_vendeur"
End With
'Dictionnaire market
With Worksheets("Feuil1")
Lastlig = .Cells(.Rows.Count, 1).End(xlUp).Row
Set marketDico = CreateObject("Scripting.Dictionary")
For f = 2 To Lastlig
If Not marketDico.Exists(.Cells(f, 3).Value) Then
marketDico.Add .Cells(f, 3).Value, .Cells(f, 3).Value
ReDim Preserve tab_market(1 To marketDico.Count)
tab_market(marketDico.Count) = .Cells(f, 3).Value
'Debug.Print MonDico.Count, Tab_asin(MonDico.Count)
End If
Next f
End With
'Stockage DOMO EXPRESS
With Worksheets("Feuil1")
q = 0
l2 = 2
While l2 <= Lastlig
If .Cells(l2, 4) = "DOMO EXPRESS" Then
q = q + 1
ReDim Preserve tab_domo(1 To 8, 1 To q)
tab_domo(1, q) = .Cells(l2, 1)
tab_domo(2, q) = .Cells(l2, 2)
tab_domo(3, q) = .Cells(l2, 3)
tab_domo(4, q) = .Cells(l2, 4)
tab_domo(5, q) = Replace(.Cells(l2, 5), ".", ",")
tab_domo(6, q) = .Cells(l2, 6)
tab_domo(7, q) = .Cells(l2, 7)
tab_domo(8, q) = .Cells(l2, 8)
End If
l2 = l2 + 1
Wend
End With
With Worksheets("Feuil3")
For r1 = 1 To UBound(tab_domo, 1)
For r2 = 1 To UBound(tab_domo, 2)
.Cells(r2 + 1, r1) = tab_domo(r1, r2)
Next r2
Next r1
End With
For g = 1 To UBound(tab_market, 1)
o = 0
e = 2
Sheets.Add.Move After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = tab_market(g)
ReDim tab_tmp_market(1 To 8, 1 To 1)
With Worksheets("Feuil1")
While e < Lastlig
If .Cells(e, 3) = tab_market(g) Then
o = o + 1
ReDim Preserve tab_tmp_market(1 To 8, 1 To o)
tab_tmp_market(1, o) = .Cells(e, 1)
tab_tmp_market(2, o) = .Cells(e, 2)
tab_tmp_market(3, o) = .Cells(e, 3)
tab_tmp_market(4, o) = .Cells(e, 4)
tab_tmp_market(5, o) = Replace(.Cells(e, 5), ".", ",")
tab_tmp_market(6, o) = .Cells(e, 6)
tab_tmp_market(7, o) = .Cells(e, 7)
tab_tmp_market(8, o) = .Cells(e, 8)
End If
e = e + 1
Wend
End With
With Worksheets("Feuil1")
'Dictionnaire ASIN
Set MonDico = CreateObject("Scripting.Dictionary")
For k = 1 To UBound(tab_tmp_market, 2)
If Not MonDico.Exists(tab_tmp_market(2, k)) Then
MonDico.Add tab_tmp_market(2, k), tab_tmp_market(2, k)
ReDim Preserve Tab_asin(1 To MonDico.Count)
Tab_asin(MonDico.Count) = tab_tmp_market(2, k)
'Debug.Print MonDico.Count, Tab_asin(MonDico.Count)
End If
Next k
End With
t = 1
'Creation du tableau temporaire par ASIN
For i = 1 To UBound(Tab_asin, 1)
p = 0
l = 1
domo = 0
ReDim tab_tmp(1 To 8, 1 To 1)
While l <= UBound(tab_tmp_market, 2)
If tab_tmp_market(2, l) = Tab_asin(i) Then
p = p + 1
ReDim Preserve tab_tmp(1 To 8, 1 To p)
tab_tmp(1, p) = tab_tmp_market(1, l)
tab_tmp(2, p) = tab_tmp_market(2, l)
tab_tmp(3, p) = tab_tmp_market(3, l)
tab_tmp(4, p) = tab_tmp_market(4, l)
If tab_tmp(4, p) = "DOMO EXPRESS" Then domo = 1
tab_tmp(5, p) = tab_tmp_market(5, l)
tab_tmp(6, p) = tab_tmp_market(6, l)
tab_tmp(7, p) = tab_tmp_market(7, l)
tab_tmp(8, p) = tab_tmp_market(8, l)
End If
l = l + 1
Wend
If domo = 1 Then
'Comparaison des prix du tableau
sku = tab_tmp(1, 1)
Asin = tab_tmp(2, 1)
market = tab_tmp(3, 1)
vendeur = tab_tmp(4, 1)
prix = tab_tmp(5, 1)
fba = tab_tmp(6, 1)
Date_file = tab_tmp(7, 1)
note = tab_tmp(8, 1)
For j = 2 To UBound(tab_tmp, 2)
If prix > tab_tmp(5, j) Then
sku = tab_tmp(1, j)
Asin = tab_tmp(2, j)
market = tab_tmp(3, j)
vendeur = tab_tmp(4, j)
prix = tab_tmp(5, j)
fba = tab_tmp(6, j)
Date_file = tab_tmp(7, j)
note = tab_tmp(8, j)
End If
Next j
'Ecriture du prix le moins cher
With Worksheets(tab_market(g))
If vendeur <> "DOMO EXPRESS" And prix <> WorksheetFunction.VLookup(Asin, Sheets("Feuil3").Range("B1:E5000"), 4, False) Then
t = t + 1
.Cells(1, 1) = "SKU"
.Cells(1, 2) = "ASIN"
.Cells(1, 3) = "Marketplace"
.Cells(1, 4) = "Nom_vendeur"
.Cells(1, 5) = "Prix"
.Cells(1, 6) = "FBA"
.Cells(1, 7) = "Date"
.Cells(1, 8) = "Note_du_vendeur"
.Cells(1, 9) = "Notre prix"
.Cells(1, 10) = "Notre marge"
.Cells(t, 1) = sku
.Cells(t, 2) = Asin
.Cells(t, 3) = market
.Cells(t, 4) = vendeur
.Cells(t, 5) = prix
.Cells(t, 6) = fba
.Cells(t, 7) = Date_file
.Cells(t, 8) = note
.Cells(t, 9) = WorksheetFunction.VLookup(Asin, Sheets("Feuil3").Range("B1:E5000"), 4, False)
End If
End With
End If
Next i
Next g
End Sub |
Partager