Problème macro export

Bonjour à tous,

J'ai un problème pour traduire mon pseudo code en VBA. J'ai un classeur avec deux feuille nommées "feuil1" et "feuil2", je souhaiterais exporter des données de feuill1 vers feuill2.

Voici le pseudo code :

Subroutine export (cemois String)

MOIS <- [SEPT, OCT, NOV, ... , MAI, JUIN]

m = indice de "cemois" dans le tableau MOIS

LEGUME <- [pdt, carrotes, navet, chou]

Cellule1 = rechercher le caractère "leg" dans la feuill1

col1 = colonne de la Cellule1

Pour Chaque legume Dans LEGUME Faire

Cellule3 = rechercher legume dans toute la feuil1

lig1 = ligne de la Cellule3

Cellule4 = rechercher legume dans toute la feuil2

lig2 = ligne de la Cellule4

Copier feuill1.Cellule(lig1,col1) vers feuil2.Cellule(lig2, m)

FinPour

Fin

Voilà ce que j'ai fait comme fonction :

Public Sub export(cemois As String)

Dim MOIS(10) As String

MOIS(0) = "SEPT"

MOIS(1) = "OCT"

MOIS(2) = "NOV"

MOIS(3) = "DEC"

MOIS(4) = "JAN"

MOIS(5) = "FEV"

MOIS(6) = "MARS"

MOIS(7) = "AVRIL"

MOIS(8) = "MAI"

MOIS(9) = "JUIN"

Dim m As Integer

m = Application.WorksheetFunction.Match(cemois, MOIS, 0)

'FIN

Dim LEGUME(3) As String

LYCEE(0) = "pdt"

LYCEE(1) = "chou"

LYCEE(2) = "carottes"

Dim Cell1 As Range, Cell2 As Range, Cell3 As Range, Cell4 As Range

Dim col1 As Double, col2 As Double, lig1 As Double, lig2 As Double

Cell1 = Worksheet("MOIS").Cells.Find(What:="leg", After:=Cells(1, 1), MatchCase:=False)

col1 = Cell1.Column

For Each Leg In LEGUME

Cell3 = Worksheet("feuil1").Cells.Find(What:=Leg, After:=Cells(1, 1), MatchCase:=False)

lig1 = Cell3.Row

Cell4 = Worksheet("feuil2").Cells.Find(What:=Leg, After:=Cells(1, 1), MatchCase:=False)

lig2 = Cell4.Row

Sheets("feuil2").Cells(lig1, col1).Value = Sheets("feuil1").Cells(lig2, m).Value

Next Leg

End Sub

Mais cela ne fonctionne pas, je ne sais pas si c'est une fonction qui est mal utilisée ou autre. Merci à tous pour votre aide.

Un petit fichier Excel avec un exemple et le code qui fonctionne mal svp ?

Voici le classeur correspondant,

Cordialement.

13monclasseur.zip (6.37 Ko)
Rechercher des sujets similaires à "probleme macro export"