AIde pour erreur d'execution '9' dans vba

yyrkoun Messages postés 4 Date d'inscription jeudi 14 janvier 2010 Statut Membre Dernière intervention 14 janvier 2010 - 14 janv. 2010 à 12:36
yyrkoun Messages postés 4 Date d'inscription jeudi 14 janvier 2010 Statut Membre Dernière intervention 14 janvier 2010 - 14 janv. 2010 à 14:27
Bonjour,

je suis débutant sur vba et j'ai un problème sur une macro, mes compétences vba restent très limités pouvez-vous m'aider sur ce sujet je vous joins le screener de ma macro vba
A noter que c'est ReDim nbjweek(1 To nbweek, 1) qui ne fonctionne pas

Je vous remercie d'avance pr votre solidarité
tres bonne année
cdt,



Sub transfoweek(nblmax1)

Dim nblweek As Variant
Dim transfomat As Variant
Dim aboutimat As Variant
Dim totaboutimat As Variant
Dim transfoaboutimat As Variant
nbweek = 0

For i = 2 To nblmax1
If Feuil1.Cells(i, 12).Value = "Total hebdo HT" Then
nbweek = nbweek + 1
End If
Next i


ReDim nbjweek(1 To nbweek, 1)
ReDim transfomat(1 To nbweek, 1)
ReDim aboutimat(1 To nbweek, 1)
ReDim totaboutimat(1 To nbweek, 1)
ReDim transfoaboutimat(1 To nbweek, 1)
firstl = 2
lastj = 0

For i = 1 To nbweek

nblweek = 0

For j = 1 To 3000
If Feuil1.Cells(j + firstl, 1).Value = Feuil1.Cells(firstl + j - 1, 1).Value Then
nblweek = nblweek + 1
Else

6 réponses

ucfoutu Messages postés 18038 Date d'inscription lundi 7 décembre 2009 Statut Modérateur Dernière intervention 11 avril 2018 211
14 janv. 2010 à 13:36
bonjour,

1)= et que vaut donc nbweek lorsque l'erreur surgit ?
2) on ne voit (mais c'est autre chose) ni la fin de la boucle J ni celle du If, dans :

For i = 1 To nbweek

nblweek = 0

For j = 1 To 3000
If Feuil1.Cells(j + firstl, 1).Value = Feuil1.Cells(firstl + j - 1, 1).Value Then
nblweek = nblweek + 1
Else 


!
On doit alors deviner ?


Les deux réponses sont indispensables ...
____________________
Très intéressante fable, L'OISELEUR, L'AUTOUR ET L'ALOUETTE !
Cliquer sur "Réponse acceptée" (en bas d'une solution avérée adéquate) rendra service à d'autres. PENSEZ-Y.
0
yyrkoun Messages postés 4 Date d'inscription jeudi 14 janvier 2010 Statut Membre Dernière intervention 14 janvier 2010
14 janv. 2010 à 13:46
Sub transfoweek(nblmax1)

Dim nblweek As Variant
Dim transfomat As Variant
Dim aboutimat As Variant
Dim totaboutimat As Variant
Dim transfoaboutimat As Variant
nbweek = 0

For i = 2 To nblmax1
If Feuil1.Cells(i, 12).Value = "Total hebdo HT" Then
nbweek = nbweek + 1
End If
Next i


ReDim nbjweek(1 To nbweek, 1)
ReDim transfomat(1 To nbweek, 1)
ReDim aboutimat(1 To nbweek, 1)
ReDim totaboutimat(1 To nbweek, 1)
ReDim transfoaboutimat(1 To nbweek, 1)
firstl = 2
lastj = 0

For i = 1 To nbweek

nblweek = 0

For j = 1 To 3000
If Feuil1.Cells(j + firstl, 1).Value = Feuil1.Cells(firstl + j - 1, 1).Value Then
nblweek = nblweek + 1
Else
Exit For
End If
Next j

lastj = nblweek + firstl
transfocompte = 0
abouticompte = 0
totabouti = 0
transfoabouti = 0
For j = firstl To lastj
If Feuil1.Cells(j, 12).Value = "O" Then
transfocompte = transfocompte + 1
End If
If UCase(Feuil1.Cells(j, 10).Value) = "O" Then
abouticompte = abouticompte + 1
End If
Next j
For j = firstl To lastj
If UCase(Feuil1.Cells(j, 10).Value) "O" Or UCase(Feuil1.Cells(j, 10).Value) "N" Then
totabouti = totabouti + 1
End If
Next j
For j = firstl To lastj
If UCase(Feuil1.Cells(j, 10).Value) "O" And UCase(Feuil1.Cells(j, 12).Value) "O" Then
transfoabouti = transfoabouti + 1
End If
Next j
transfoaboutimat(i, 1) = transfoabouti
totaboutimat(i, 1) = totabouti
aboutimat(i, 1) = abouticompte
transfomat(i, 1) = transfocompte
nbjweek(i, 1) = lastj - firstl + 1
firstl = lastj + 2

Next i

For i = 1 To nbweek
Feuil3.Cells(i + 2, 4).Value = transfomat(i, 1) / nbjweek(i, 1)
Feuil3.Cells(i + 2, 5).Value = nbjweek(i, 1)
If totaboutimat(i, 1) = 0 Then
Feuil3.Cells(i + 2, 6).Value = "div0"
Else
Feuil3.Cells(i + 2, 6).Value = aboutimat(i, 1) / totaboutimat(i, 1)
End If
If aboutimat(i, 1) = 0 Then
Feuil3.Cells(i + 2, 7).Value = "div0"
Else
Feuil3.Cells(i + 2, 7).Value = transfoaboutimat(i, 1) / aboutimat(i, 1)
End If
Next i
0
pile_poil Messages postés 682 Date d'inscription vendredi 6 avril 2007 Statut Membre Dernière intervention 4 août 2012 6
14 janv. 2010 à 13:46
tu déclares :
Dim nblweek As Variant
Dim transfomat As Variant
Dim aboutimat As Variant
Dim totaboutimat As Variant
Dim transfoaboutimat As Variant 


puis tu dimensionnes

ReDim nbjweek(1 To nbweek, 1)
ReDim transfomat(1 To nbweek, 1)
ReDim aboutimat(1 To nbweek, 1)
ReDim totaboutimat(1 To nbweek, 1)
ReDim transfoaboutimat(1 To nbweek, 1)



premier problem la déclaration et le redimensinnement ne sont pas sur le meme nom nbjweek <> nblweek
de plus pour faire un redim il faut déclarer un array
Dim nblweek As Variant

devrait être:
Dim nblweek() As Variant


si j'ai raison tu aura la meme erreur sur les quatres lignes suivantes pour la meme raison

si c'est la solution, penser : REPONSE ACCEPTEE
0
yyrkoun Messages postés 4 Date d'inscription jeudi 14 janvier 2010 Statut Membre Dernière intervention 14 janvier 2010
14 janv. 2010 à 13:52
Merci mais cela ne fonctionne tjrs pas qu'entendez vous par "premier problem la déclaration et le redimensinnement ne sont pas sur le meme nom nbjweek <> nblweek " dois e changer nbjweek en nblweek?
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
pile_poil Messages postés 682 Date d'inscription vendredi 6 avril 2007 Statut Membre Dernière intervention 4 août 2012 6
14 janv. 2010 à 14:17
soit l'un soit l'autre mais pas tantot l'un tantot l'autre pour la meme chose !

en fait ton erreur vien du fait que tu mets nbweek à 0
si dans la boucle qui suit la condition n'est jamais remplie quand tu fais ton redim
ReDim nbjweek(1 To nbweek, 1)

le "1 to nbweek" le fait grincer des dents car 1 to 0
vb il sait pas trop ce que ça veut dire
donc
remplace nbweek =0

par
dim nbweek as integer
nbweek = 1 



si c'est la solution, penser : REPONSE ACCEPTEE
0
yyrkoun Messages postés 4 Date d'inscription jeudi 14 janvier 2010 Statut Membre Dernière intervention 14 janvier 2010
14 janv. 2010 à 14:27
merci le code fonctionne il n'affiche plsu d'erreur mais il ne va pas rechercher pas toutes les valeurs avez vous une idée pourquoi?
0
Rejoignez-nous