XL 2010 VBA: Création nouveau classeur Excel

TheProdigy

XLDnaute Impliqué
Bonjour le Forum,

Je voudrais appliquer mon code sur une feuille d'un nouveau classeur au lieu de la feuille "Objectif"

Code:
Sub test()

Dim A As Variant, b As Variant, c As Variant, d As Variant, e As Variant, f As Variant, ligne As Long, x As String
tablo = Sheets("Items").Range("C2:M" & Sheets("Items").Range("C" & Rows.Count).End(xlUp).Row)
Set dico = CreateObject("Scripting.dictionary")
Set achat = CreateObject("Scripting.dictionary")
Set vente = CreateObject("Scripting.dictionary")
Set stock = CreateObject("Scripting.dictionary")
Set ladate = CreateObject("Scripting.dictionary")
For n = LBound(tablo, 1) To UBound(tablo, 1)
If tablo(n, 7) <= ladatefin Then
   x = tablo(n, 1) & "|" & tablo(n, 2) & "|" & tablo(n, 3) & "|" & tablo(n, 4) & "|" & tablo(n, 5)
   ladate(x) = tablo(n, 7)
   If tablo(n, 6) = "Achat" Or tablo(n, 6) = "Sous" Or tablo(n, 6) = "AchatAll" Or tablo(n, 6) = "AchatTr" Then
      dico(x) = dico(x) + tablo(n, 8)
      achat(x) = achat(x) + tablo(n, 10)
      vente(x) = vente(x) + 0
      stock(x) = stock(x) + 0
   Else
     dico(x) = dico(x) - tablo(n, 8)
     vente(x) = vente(x) + tablo(n, 10)
     achat(x) = achat(x) + 0
     stock(x) = stock(x) + tablo(n, 11)
   End If
  End If
Next
A = dico.keys
b = dico.items
c = ladate.items
d = achat.items
e = vente.items
f = stock.items
Sheets("items").Unprotect
Sheets("Objectif").Cells.ClearContents
ligne = 2
    Sheets("Objectif").Cells(1, 4) = "Mu"
    Sheets("Objectif").Cells(1, 5) = "Aff1"
    Sheets("Objectif").Cells(1, 6) = "Aff2"
    Sheets("Objectif").Cells(1, 7) = "Type"
    Sheets("Objectif").Cells(1, 8) = "Libellé"
    Sheets("Objectif").Cells(1, 9) = "Opération"
    Sheets("Objectif").Cells(1, 10) = "Date"
    Sheets("Objectif").Cells(1, 11) = "Nombre"
    Sheets("Objectif").Cells(1, 12) = "Acq"
    Sheets("Objectif").Cells(1, 13) = "Vente"
    Sheets("Objectif").Cells(1, 14) = "CS"
For n = LBound(A) To UBound(A)
   Sheets("Objectif").Cells(ligne, 4) = Split(A(n), "|")(0)
   Sheets("Objectif").Cells(ligne, 5) = Split(A(n), "|")(1)
   Sheets("Objectif").Cells(ligne, 6) = Split(A(n), "|")(2)
   Sheets("Objectif").Cells(ligne, 7) = Split(A(n), "|")(4)
   Sheets("Objectif").Cells(ligne, 8) = Split(A(n), "|")(3)
   Sheets("Objectif").Cells(ligne, 9) = "stock"
   Sheets("Objectif").Cells(ligne, 10) = c(n)
   Sheets("Objectif").Cells(ligne, 11) = b(n)
   Sheets("Objectif").Cells(ligne, 12) = d(n)
   Sheets("Objectif").Cells(ligne, 13) = e(n)
   Sheets("Objectif").Cells(ligne, 14) = f(n)
   ligne = ligne + 1
Next
Sheets("Objectif").Select
Unload UserForm5
Unload UserForm1
Sheets("Items").Protect
End Sub

Merci
 

Discussions similaires

Réponses
17
Affichages
808

Statistiques des forums

Discussions
312 115
Messages
2 085 451
Membres
102 889
dernier inscrit
monsef JABBOUR