Ca Bug , pourquoi?
Le
S3com
Bonjour a tous!
j'ai fait ce code (avec un peu d'aide) :-) Mais là ca bug ! Voici la
partie ou ca bloque :
For i = 0 To Sheets(i).ListeFeuilles.ListCount - 1
et voici ce bout dans tout son contexte: (cette macro est executer
depuis un bouton situé sur une feuille appelée ACCEUIL. (si ca peut
aider)
QU'est ce qui ne vas pas dans mon code? Toutes remarques le concernant
sont bonnes a prendre!!!
MERCI avec un grand M !
Sub resultat()
Dim j, tbl_names, nm, dpts, myrg As Range
Dim ong As Integer
Application.ScreenUpdating = False
'classe ordre alphabetique
'verifie correspondance nom onglet/fournisseur
For m = 3 To Sheets.Count
Sheets(m).Select
Cells(4, 1).Value = Sheets(m).Name
For p = m To Sheets.Count
If UCase(Sheets(p).Name) < UCase(Sheets(m).Name) Then
Sheets(p).Move Sheets(m)
End If
Next p
Next m
'verifie si feuille existe déja
k = 1
While Not k = Sheets.Count + 1
Sheets(k).Select
If Sheets(k).Name = "Recap" Then
''''''' Ca ça t'évite de valider par la touche entrée quand la
feuille est supprimmée
Application.SendKeys ("{enter}")
Sheets(k).Delete
''''''je repositionne l'indice de la feuille testée
k = k - 1
End If
k = k + 1
Wend
'--ajoute une feuille au classeur actif
Sheets(2).Select
Sheets.Add
Sheets(2).Select
Sheets(2).Name = "Recap"
'--Definition des entetes de colonnes(2 lignes)
With Sheets("recap").Select
[A1].Value = "Rayon"
[B1].Value = "Nom Fournisseurs"
[C1].Value = "Téléphone Siège"
[D1].Value = "E-mail representant 1"
[E1].Value = "E-mail representant 2"
[F1].Value = "Nom représentant 1"
[G1].Value = "Nom représentant 2"
[H1].Value = "Ca prévisionnel"
[I1].Value = "Salon"
[J1].Value = "Valeur Salon"
[K1].Value = "MEA"
[L1].Value = "Valeur MEA"
[M1].Value = "Prospectus"
[N1].Value = "Valeur Prospectus"
[O1].Value = "Package évenement"
[P1].Value = "Valeur Pack. Even."
[Q1].Value = "Prestation logistique"
[R1].Value = "Valeur Prest. Log."
[S1].Value = "Préco Merch."
[T1].Value = "Valeur Préco. Merch."
[U1].Value = "Stats SCA"
[V1].Value = "Valeur Stats"
[W1].Value = "Somme"
With [A1].CurrentRegion
.Interior.Color = 255
.Font.ColorIndex = 2
.Font.Name = "Arial"
End With
End With
For i = 0 To Sheets(i).ListeFeuilles.ListCount - 1
If Sheets(1).ListeFeuilles.Selected(i) = True Then
nf = Sheets(1).ListeFeuilles.List(i)
'nf est le n° de la feuille detenant les informations a copier
'si formules
Sheets(nf).[A4].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 1).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
ActiveSheet.Hyperlinks.Add anchor:=Selection, Address:="",
SubAddress:=Sheets(nf).Name & "!A1"
'si formules
Sheets(nf).[A8].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 2).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[B8].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 3).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[D8].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 4).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[B10].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 5).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[D10].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 6).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[E13].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 7).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[E71].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 8).Select
ActiveSheet.Paste Link:=True
For X = 9 To 21 Step 2
Sheets("recap").[A65000].End(xlUp).Offset(1, X).Value =
"=RC[-2]*RC[-1]"
Next X
'si formules
Sheets(nf).[E51].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 10).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[E52].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 12).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[E54].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 14).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[E55].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 16).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[E68].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 18).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[E69].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 20).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
Sheets("recap").[A65000].End(xlUp).Offset(1, 22).Value =
"=RC[-1]+RC[-3]+RC[-5]+RC[-7]+RC[-9]+RC[-11]+RC[-13]"
'Validation a mettre en dernier
Sheets(nf).[E4].Copy 'A4 est la cellule de départ
' offset va selectionner une autre cellule a partir de A3
Sheets("recap").[A65000].End(xlUp).Offset(1, 0).PasteSpecial
(xlPasteValues)
End If
Next i
[A1].CurrentRegion.Columns.AutoFit
End Sub
j'ai fait ce code (avec un peu d'aide) :-) Mais là ca bug ! Voici la
partie ou ca bloque :
For i = 0 To Sheets(i).ListeFeuilles.ListCount - 1
et voici ce bout dans tout son contexte: (cette macro est executer
depuis un bouton situé sur une feuille appelée ACCEUIL. (si ca peut
aider)
QU'est ce qui ne vas pas dans mon code? Toutes remarques le concernant
sont bonnes a prendre!!!
MERCI avec un grand M !
Sub resultat()
Dim j, tbl_names, nm, dpts, myrg As Range
Dim ong As Integer
Application.ScreenUpdating = False
'classe ordre alphabetique
'verifie correspondance nom onglet/fournisseur
For m = 3 To Sheets.Count
Sheets(m).Select
Cells(4, 1).Value = Sheets(m).Name
For p = m To Sheets.Count
If UCase(Sheets(p).Name) < UCase(Sheets(m).Name) Then
Sheets(p).Move Sheets(m)
End If
Next p
Next m
'verifie si feuille existe déja
k = 1
While Not k = Sheets.Count + 1
Sheets(k).Select
If Sheets(k).Name = "Recap" Then
''''''' Ca ça t'évite de valider par la touche entrée quand la
feuille est supprimmée
Application.SendKeys ("{enter}")
Sheets(k).Delete
''''''je repositionne l'indice de la feuille testée
k = k - 1
End If
k = k + 1
Wend
'--ajoute une feuille au classeur actif
Sheets(2).Select
Sheets.Add
Sheets(2).Select
Sheets(2).Name = "Recap"
'--Definition des entetes de colonnes(2 lignes)
With Sheets("recap").Select
[A1].Value = "Rayon"
[B1].Value = "Nom Fournisseurs"
[C1].Value = "Téléphone Siège"
[D1].Value = "E-mail representant 1"
[E1].Value = "E-mail representant 2"
[F1].Value = "Nom représentant 1"
[G1].Value = "Nom représentant 2"
[H1].Value = "Ca prévisionnel"
[I1].Value = "Salon"
[J1].Value = "Valeur Salon"
[K1].Value = "MEA"
[L1].Value = "Valeur MEA"
[M1].Value = "Prospectus"
[N1].Value = "Valeur Prospectus"
[O1].Value = "Package évenement"
[P1].Value = "Valeur Pack. Even."
[Q1].Value = "Prestation logistique"
[R1].Value = "Valeur Prest. Log."
[S1].Value = "Préco Merch."
[T1].Value = "Valeur Préco. Merch."
[U1].Value = "Stats SCA"
[V1].Value = "Valeur Stats"
[W1].Value = "Somme"
With [A1].CurrentRegion
.Interior.Color = 255
.Font.ColorIndex = 2
.Font.Name = "Arial"
End With
End With
For i = 0 To Sheets(i).ListeFeuilles.ListCount - 1
If Sheets(1).ListeFeuilles.Selected(i) = True Then
nf = Sheets(1).ListeFeuilles.List(i)
'nf est le n° de la feuille detenant les informations a copier
'si formules
Sheets(nf).[A4].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 1).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
ActiveSheet.Hyperlinks.Add anchor:=Selection, Address:="",
SubAddress:=Sheets(nf).Name & "!A1"
'si formules
Sheets(nf).[A8].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 2).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[B8].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 3).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[D8].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 4).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[B10].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 5).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[D10].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 6).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[E13].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 7).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[E71].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 8).Select
ActiveSheet.Paste Link:=True
For X = 9 To 21 Step 2
Sheets("recap").[A65000].End(xlUp).Offset(1, X).Value =
"=RC[-2]*RC[-1]"
Next X
'si formules
Sheets(nf).[E51].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 10).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[E52].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 12).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[E54].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 14).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[E55].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 16).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[E68].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 18).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[E69].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 20).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
Sheets("recap").[A65000].End(xlUp).Offset(1, 22).Value =
"=RC[-1]+RC[-3]+RC[-5]+RC[-7]+RC[-9]+RC[-11]+RC[-13]"
'Validation a mettre en dernier
Sheets(nf).[E4].Copy 'A4 est la cellule de départ
' offset va selectionner une autre cellule a partir de A3
Sheets("recap").[A65000].End(xlUp).Offset(1, 0).PasteSpecial
(xlPasteValues)
End If
Next i
[A1].CurrentRegion.Columns.AutoFit
End Sub

Poser une question


Indice en dehors de la plage (erreur 9)
moi je mettrais
For i = 1 To Sheets.Count
ou
For i = 0 To Sheets.Count - 1
a+
gerard
"S3com"
Bonjour a tous!
j'ai fait ce code (avec un peu d'aide) :-) Mais là ca bug ! Voici la
partie ou ca bloque :
For i = 0 To Sheets(i).ListeFeuilles.ListCount - 1
et voici ce bout dans tout son contexte: (cette macro est executer
depuis un bouton situé sur une feuille appelée ACCEUIL. (si ca peut
aider)
QU'est ce qui ne vas pas dans mon code? Toutes remarques le concernant
sont bonnes a prendre!!!
MERCI avec un grand M !
Sub resultat()
Dim j, tbl_names, nm, dpts, myrg As Range
Dim ong As Integer
Application.ScreenUpdating = False
'------classe ordre alphabetique
'------verifie correspondance nom onglet/fournisseur
For m = 3 To Sheets.Count
Sheets(m).Select
Cells(4, 1).Value = Sheets(m).Name
For p = m To Sheets.Count
If UCase(Sheets(p).Name) Sheets(p).Move Sheets(m)
End If
Next p
Next m
'------verifie si feuille existe déja
k = 1
While Not k = Sheets.Count + 1
Sheets(k).Select
If Sheets(k).Name = "Recap" Then
''''''' Ca ça t'évite de valider par la touche entrée quand la
feuille est supprimmée
Application.SendKeys ("{enter}")
Sheets(k).Delete
''''''je repositionne l'indice de la feuille testée
k = k - 1
End If
k = k + 1
Wend
'--------ajoute une feuille au classeur actif
Sheets(2).Select
Sheets.Add
Sheets(2).Select
Sheets(2).Name = "Recap"
'--------Definition des entetes de colonnes(2 lignes)
With Sheets("recap").Select
[A1].Value = "Rayon"
[B1].Value = "Nom Fournisseurs"
[C1].Value = "Téléphone Siège"
[D1].Value = "E-mail representant 1"
[E1].Value = "E-mail representant 2"
[F1].Value = "Nom représentant 1"
[G1].Value = "Nom représentant 2"
[H1].Value = "Ca prévisionnel"
[I1].Value = "Salon"
[J1].Value = "Valeur Salon"
[K1].Value = "MEA"
[L1].Value = "Valeur MEA"
[M1].Value = "Prospectus"
[N1].Value = "Valeur Prospectus"
[O1].Value = "Package évenement"
[P1].Value = "Valeur Pack. Even."
[Q1].Value = "Prestation logistique"
[R1].Value = "Valeur Prest. Log."
[S1].Value = "Préco Merch."
[T1].Value = "Valeur Préco. Merch."
[U1].Value = "Stats SCA"
[V1].Value = "Valeur Stats"
[W1].Value = "Somme"
With [A1].CurrentRegion
.Interior.Color = 255
.Font.ColorIndex = 2
.Font.Name = "Arial"
End With
End With
For i = 0 To Sheets(i).ListeFeuilles.ListCount - 1
If Sheets(1).ListeFeuilles.Selected(i) = True Then
nf = Sheets(1).ListeFeuilles.List(i)
'nf est le n° de la feuille detenant les informations a copier
'si formules
Sheets(nf).[A4].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 1).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
ActiveSheet.Hyperlinks.Add anchor:=Selection, Address:="",
SubAddress:=Sheets(nf).Name & "!A1"
'si formules
Sheets(nf).[A8].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 2).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[B8].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 3).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[D8].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 4).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[B10].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 5).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[D10].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 6).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[E13].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 7).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[E71].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 8).Select
ActiveSheet.Paste Link:=True
For X = 9 To 21 Step 2
Sheets("recap").[A65000].End(xlUp).Offset(1, X).Value "=RC[-2]*RC[-1]"
Next X
'si formules
Sheets(nf).[E51].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 10).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[E52].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 12).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[E54].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 14).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[E55].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 16).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[E68].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 18).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
'si formules
Sheets(nf).[E69].Copy
Sheets("recap").[A65000].End(xlUp).Offset(1, 20).Select
ActiveCell.PasteSpecial (xlPasteValues)
ActiveCell.PasteSpecial (xlPasteFormats)
ActiveSheet.Paste Link:=True
Sheets("recap").[A65000].End(xlUp).Offset(1, 22).Value "=RC[-1]+RC[-3]+RC[-5]+RC[-7]+RC[-9]+RC[-11]+RC[-13]"
'Validation a mettre en dernier
Sheets(nf).[E4].Copy 'A4 est la cellule de départ
' offset va selectionner une autre cellule a partir de A3
Sheets("recap").[A65000].End(xlUp).Offset(1, 0).PasteSpecial
(xlPasteValues)
End If
Next i
[A1].CurrentRegion.Columns.AutoFit
End Sub