Erreur de compilation
Résolu
bestkeeper
Messages postés
89
Date d'inscription
Statut
Membre
Dernière intervention
-
Polux31 Messages postés 6917 Date d'inscription Statut Membre Dernière intervention -
Polux31 Messages postés 6917 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
j'ai une erreur dans ma macro "erreur de compilation, variable non définie" sur la ligne ReDim Preserve my tab
Voici la macro :
Sub Bouton1_QuandClic()
Private myTab()
Private ind As Long
Public Sub mainTri()
prepareTri
lanceRecap
End Sub
Private Sub prepareTri()
Dim ws As Worksheet
Dim i As Long
Set ws = Worksheets(1)
i = 2
While ws.Range("A" & i).Value <> ""
If doesExist(ws.Range("A" & i).Value) = False Then
ind = ind + 1
ReDim Preserve myTab(ind)
myTab(ind) = ws.Range("A" & i).Value
End If
i = i + 1
Wend
Set ws = Nothing
End Sub
Private Sub lanceRecap()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim lig1 As Long
Dim lig2 As Long
Dim i As Long
Dim str As Variant
Set ws1 = Worksheets(1)
Set ws2 = Worksheets(2)
lig2 = 2
For i = 1 To ind
lig1 = 2
str = myTab(i)
While ws1.Range("A" & lig1).Value <> ""
If ws1.Range("A" & lig1).Value = str Then
ws1.Range("B" & lig1).Copy Destination:=ws2.Range("A" & lig2)
ws1.Range("A" & lig1).Copy Destination:=ws2.Range("B" & lig2)
ws1.Range("E" & lig1).Copy Destination:=ws2.Range("C" & lig2)
lig2 = lig2 + 1
End If
lig1 = lig1 + 1
Wend
Next i
Set ws1 = Nothing
Set ws2 = Nothing
End Sub
Private Function doesExist(ByVal str As Variant) As Boolean
Dim i As Long
For i = 1 To ind
If myTab(i) = str Then
doesExist = True
Exit Function
End If
Next i
doesExist = False
End Function
End Function
Help SVP.
Cette macro me sert à effectuer un récapitulatif de commande.
j'ai une erreur dans ma macro "erreur de compilation, variable non définie" sur la ligne ReDim Preserve my tab
Voici la macro :
Sub Bouton1_QuandClic()
Private myTab()
Private ind As Long
Public Sub mainTri()
prepareTri
lanceRecap
End Sub
Private Sub prepareTri()
Dim ws As Worksheet
Dim i As Long
Set ws = Worksheets(1)
i = 2
While ws.Range("A" & i).Value <> ""
If doesExist(ws.Range("A" & i).Value) = False Then
ind = ind + 1
ReDim Preserve myTab(ind)
myTab(ind) = ws.Range("A" & i).Value
End If
i = i + 1
Wend
Set ws = Nothing
End Sub
Private Sub lanceRecap()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim lig1 As Long
Dim lig2 As Long
Dim i As Long
Dim str As Variant
Set ws1 = Worksheets(1)
Set ws2 = Worksheets(2)
lig2 = 2
For i = 1 To ind
lig1 = 2
str = myTab(i)
While ws1.Range("A" & lig1).Value <> ""
If ws1.Range("A" & lig1).Value = str Then
ws1.Range("B" & lig1).Copy Destination:=ws2.Range("A" & lig2)
ws1.Range("A" & lig1).Copy Destination:=ws2.Range("B" & lig2)
ws1.Range("E" & lig1).Copy Destination:=ws2.Range("C" & lig2)
lig2 = lig2 + 1
End If
lig1 = lig1 + 1
Wend
Next i
Set ws1 = Nothing
Set ws2 = Nothing
End Sub
Private Function doesExist(ByVal str As Variant) As Boolean
Dim i As Long
For i = 1 To ind
If myTab(i) = str Then
doesExist = True
Exit Function
End If
Next i
doesExist = False
End Function
End Function
Help SVP.
Cette macro me sert à effectuer un récapitulatif de commande.
A voir également:
- Erreur de compilation
- Erreur 0x80070643 - Accueil - Windows
- Erreur 4101 france tv - Forum Lecteurs et supports vidéo
- J'aime par erreur facebook notification - Forum Facebook
- Code erreur f3500-31 ✓ - Forum Bbox Bouygues
- Java code erreur 1603 ✓ - Forum Windows
42 réponses
dans le dernier ensemble de ton code, la fonction doesExist() n'y est pas ... ne l'aurais-tu pas effacée ???
;o)
;o)
Ok autant pour moi, j'avais zappé cette partie de la macro.
Maintenant il me sort une erreur de compilation sur le Private Sub lanceRecap() à la ligne CallTriTab.
Maintenant il me sort une erreur de compilation sur le Private Sub lanceRecap() à la ligne CallTriTab.
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
Erreur de compilation sur cette ligne :
Je ne comprends pas, j'ai testé les procédures hier soir chez moi et ça fonctionnait, je pouvais faire le tri dans les 2 sens. Je ne vois pas d'où ça peut venir.
Call TriTab(True)
Je ne comprends pas, j'ai testé les procédures hier soir chez moi et ça fonctionnait, je pouvais faire le tri dans les 2 sens. Je ne vois pas d'où ça peut venir.
Voici la macro dans sa globalité, peut-être y verras tu une erreur ?
Option Explicit
Private myTab()
Private ind As Long
Public Sub mainTri()
prepareTri
lanceRecap
End Sub
Private Sub prepareTri()
Dim ws As Worksheet
Dim i As Long
Set ws = Worksheets("commandes")
i = 2
While ws.Range("A" & i).Value <> ""
If doesExist(ws.Range("A" & i).Value) = False Then
ind = ind + 1
ReDim Preserve myTab(ind)
myTab(ind) = ws.Range("A" & i).Value
End If
i = i + 1
Wend
Set ws = Nothing
End Sub
Private Sub lanceRecap()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim lig1 As Long
Dim lig2 As Long
Dim i As Long
Dim str As Variant
Set ws1 = Worksheets("commandes")
Set ws2 = Worksheets("recap")
lig2 = 2
Call TriTab(True) 'True tri croissant, False tri décroissant
For i = 1 To ind
lig1 = 2
str = myTab(i)
While ws1.Range("A" & lig1).Value <> ""
If ws1.Range("A" & lig1).Value = str Then
ws1.Select
ws1.Range("B" & lig1).Copy
ws2.Select
ws2.Range("A" & lig2).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ws1.Select
ws1.Range("A" & lig1).Copy
ws2.Select
ws2.Range("B" & lig2).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ws1.Select
ws1.Range("E" & lig1).Copy
ws2.Select
ws2.Range("C" & lig2).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
lig2 = lig2 + 1
End If
lig1 = lig1 + 1
Wend
Next i
Set ws1 = Nothing
Set ws2 = Nothing
End Sub
Private Function doesExist(ByVal str As Variant) As Boolean
Dim i As Long
For i = 1 To ind
If myTab(i) = str Then
doesExist = True
Exit Function
End If
Next i
doesExist = False
End Function
Option Explicit
Private myTab()
Private ind As Long
Public Sub mainTri()
prepareTri
lanceRecap
End Sub
Private Sub prepareTri()
Dim ws As Worksheet
Dim i As Long
Set ws = Worksheets("commandes")
i = 2
While ws.Range("A" & i).Value <> ""
If doesExist(ws.Range("A" & i).Value) = False Then
ind = ind + 1
ReDim Preserve myTab(ind)
myTab(ind) = ws.Range("A" & i).Value
End If
i = i + 1
Wend
Set ws = Nothing
End Sub
Private Sub lanceRecap()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim lig1 As Long
Dim lig2 As Long
Dim i As Long
Dim str As Variant
Set ws1 = Worksheets("commandes")
Set ws2 = Worksheets("recap")
lig2 = 2
Call TriTab(True) 'True tri croissant, False tri décroissant
For i = 1 To ind
lig1 = 2
str = myTab(i)
While ws1.Range("A" & lig1).Value <> ""
If ws1.Range("A" & lig1).Value = str Then
ws1.Select
ws1.Range("B" & lig1).Copy
ws2.Select
ws2.Range("A" & lig2).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ws1.Select
ws1.Range("A" & lig1).Copy
ws2.Select
ws2.Range("B" & lig2).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
ws1.Select
ws1.Range("E" & lig1).Copy
ws2.Select
ws2.Range("C" & lig2).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
lig2 = lig2 + 1
End If
lig1 = lig1 + 1
Wend
Next i
Set ws1 = Nothing
Set ws2 = Nothing
End Sub
Private Function doesExist(ByVal str As Variant) As Boolean
Dim i As Long
For i = 1 To ind
If myTab(i) = str Then
doesExist = True
Exit Function
End If
Next i
doesExist = False
End Function
bonjour
myTab() doit être déclaré en variable global du module et non dans une procédure.
Tu as "Sub Bouton1_QuandClic()" qui n'a rien à faire ici puisque pas de End Sub.
Idem pourquoi 2 fois End Function à la fin ????
;o)
myTab() doit être déclaré en variable global du module et non dans une procédure.
Tu as "Sub Bouton1_QuandClic()" qui n'a rien à faire ici puisque pas de End Sub.
Idem pourquoi 2 fois End Function à la fin ????
;o)
J'ai apporté les modifications.
Le hic, est que cela ne me prends en compte que les données de la première page.
Le hic, est que cela ne me prends en compte que les données de la première page.
Il faut modifier l'objet Worksheets().
Faire : Set ws = Worksheets("nom_de_l'onglet") ou lieu de Worksheets(1) par exemple.
;o)
Faire : Set ws = Worksheets("nom_de_l'onglet") ou lieu de Worksheets(1) par exemple.
;o)
ça ne marche toujours pas.
Option Explicit
Private myTab()
Private ind As Long
Public Sub mainTri()
prepareTri
lanceRecap
End Sub
Private Sub prepareTri()
Dim ws As Worksheet
Dim i As Long
Set ws = Worksheets("commandes")
i = 2
While ws.Range("A" & i).Value <> ""
If doesExist(ws.Range("A" & i).Value) = False Then
ind = ind + 1
ReDim Preserve myTab(ind)
myTab(ind) = ws.Range("A" & i).Value
End If
i = i + 1
Wend
Set ws = Nothing
End Sub
Private Sub lanceRecap()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim lig1 As Long
Dim lig2 As Long
Dim i As Long
Dim str As Variant
Set ws1 = Worksheets("commandes")
Set ws2 = Worksheets("recap")
lig2 = 2
For i = 1 To ind
lig1 = 2
str = myTab(i)
While ws1.Range("A" & lig1).Value <> ""
If ws1.Range("A" & lig1).Value = str Then
ws1.Range("B" & lig1).Copy Destination:=ws2.Range("A" & lig2)
ws1.Range("A" & lig1).Copy Destination:=ws2.Range("B" & lig2)
ws1.Range("E" & lig1).Copy Destination:=ws2.Range("C" & lig2)
lig2 = lig2 + 1
End If
lig1 = lig1 + 1
Wend
Next i
Set ws1 = Worksheets("commandes")
Set ws2 = Worksheets("recap")
End Sub
Private Function doesExist(ByVal str As Variant) As Boolean
Dim i As Long
For i = 1 To ind
If myTab(i) = str Then
doesExist = True
Exit Function
End If
Next i
doesExist = False
End Function
Option Explicit
Private myTab()
Private ind As Long
Public Sub mainTri()
prepareTri
lanceRecap
End Sub
Private Sub prepareTri()
Dim ws As Worksheet
Dim i As Long
Set ws = Worksheets("commandes")
i = 2
While ws.Range("A" & i).Value <> ""
If doesExist(ws.Range("A" & i).Value) = False Then
ind = ind + 1
ReDim Preserve myTab(ind)
myTab(ind) = ws.Range("A" & i).Value
End If
i = i + 1
Wend
Set ws = Nothing
End Sub
Private Sub lanceRecap()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim lig1 As Long
Dim lig2 As Long
Dim i As Long
Dim str As Variant
Set ws1 = Worksheets("commandes")
Set ws2 = Worksheets("recap")
lig2 = 2
For i = 1 To ind
lig1 = 2
str = myTab(i)
While ws1.Range("A" & lig1).Value <> ""
If ws1.Range("A" & lig1).Value = str Then
ws1.Range("B" & lig1).Copy Destination:=ws2.Range("A" & lig2)
ws1.Range("A" & lig1).Copy Destination:=ws2.Range("B" & lig2)
ws1.Range("E" & lig1).Copy Destination:=ws2.Range("C" & lig2)
lig2 = lig2 + 1
End If
lig1 = lig1 + 1
Wend
Next i
Set ws1 = Worksheets("commandes")
Set ws2 = Worksheets("recap")
End Sub
Private Function doesExist(ByVal str As Variant) As Boolean
Dim i As Long
For i = 1 To ind
If myTab(i) = str Then
doesExist = True
Exit Function
End If
Next i
doesExist = False
End Function
Je n'ai pas d'erreur.
La macro s'execute, et seules les données de la première page de l'onglet "commande" apparaissent.
La macro s'execute, et seules les données de la première page de l'onglet "commande" apparaissent.
C'est à cause des cellules fusionnées ou vides ... le test se fait sur la colonne A. Pour parcourir toute la feuille, il ne faut ni cellules vides en A, ni cellules fusionnées.
Ok, donc moi j'ai des cellules vides.
Je fais un test avec uniquement des cellules pleines, et je te tiens au courant.
Merci
Je fais un test avec uniquement des cellules pleines, et je te tiens au courant.
Merci