URGENTTTTT .... BESOIN D'AIDE !!

Résolu
tiago27400 Messages postés 7 Date d'inscription jeudi 23 février 2006 Statut Membre Dernière intervention 15 avril 2006 - 13 avril 2006 à 20:05
rvblog Messages postés 792 Date d'inscription vendredi 4 mars 2005 Statut Membre Dernière intervention 12 juin 2012 - 17 avril 2006 à 03:16
Bonjour à tous,
Je suis sur le point d'achever un programme de solveur de Sudoku, mais j'affronte un problème devant lequel je n'arrive pas à m'en sortir, je fais appel à la solidarité de tous les programmeurs ... c très très important !!
Mon problème est le suivant :
En executant mon programme, je vois s'afficher le message suivant :
"ERREUR D'EXECUTION 1004 : la méthode Range de l'objet _Global a échoué "
Que signifie ce message ? Comment puis-je le résoudre ? Quelqu'un est-il prêt à me filer un petit coup de pouce ?
Merci d'avance.

12 réponses

Utilisateur anonyme
13 avril 2006 à 20:53
Oui c'est un peu évidant que ca marche pas
"TopCarré" n'est pas une référence de celulle. Une référence dois être du type Colonne + Ligne (ex "A1", "EC432" ...)
Si TopCarré est une variable (je sais pas ou elle et de quel type est est), il faut pas que tu mette de '"': Range(TopCarré).[...]
Je ne peux pas faire une annalyse complete de ton code, mais c'est a ce niveau la que ca va pas.

Kenji



<HR width="100%" SIZE=2>



Merci de cliquer sur "Réponse acceptée" si une réponse vous convient.
3
cs_DARKSIDIOUS Messages postés 15814 Date d'inscription jeudi 8 août 2002 Statut Membre Dernière intervention 4 mars 2013 131
13 avril 2006 à 20:10
passe nous le bout de code qui provoque l'erreur pour qu'on puisse mieux voir, et précise le langage utilisé, car là, perso, ca me dit rien !

_
Avant de poster dans le forum,
prière d'aller lire ceci :
http://www.codes-sources.com/reglement.aspx
<s></s>
0
Utilisateur anonyme
13 avril 2006 à 20:28
Salut,

Oui, range, c'est du VBA
C'est que la référnce de ta cellule est incorecte.
Vérifie qu'elle est bonne.

Kenji

<HR width="100%" SIZE=2>


Merci de cliquer sur "Réponse acceptée" si une réponse vous convient.
0
tiago27400 Messages postés 7 Date d'inscription jeudi 23 février 2006 Statut Membre Dernière intervention 15 avril 2006
13 avril 2006 à 20:31
Oui, c du vba excel, Voici mon programme au complet : la partie en rouge est la partie à partir de lakel je bloque .. merci d'avance !

MODULE 1

Option Explicit


Public SudokuNombre(9) As Byte
Public BoiteRef(9) As String
Public ColonneMix(3) As Byte
Public LigneMix(3) As Byte
Public Carré As Byte
Public GrandCarréLigne As Byte
Public GrandCarréColonne As Byte
Public m As Byte
Public n As Byte
Public xColonne As Byte
Public xLigne As Byte
Public x As Byte
Public y As Byte
Public OuiNon As Boolean
Public ColonneOK As Boolean
Public LigneOK As Boolean
Public Place As Boolean
Public PositionJeux As Integer
Public Jouer As Byte
Public SolutionJeu As Byte
Public Tjrsolution As Boolean
Public Compteur As Byte


Sub EffacerTout()
Range("Grid").ClearContents
Range("Grid").Font.ColorIndex = 1
[b4].Select
End Sub
Sub Restaurer_jeux()
For xColonne = 0 To 8
For xLigne = 0 To 8
If Range("TopCarré").Offset(xColonne, xLigne).Font.ColorIndex <> 1 Then
Range("TopCarré").Offset(xColonne, xLigne).Font.ColorIndex = 3
Range("TopCarré").Offset(xColonne, xLigne).ClearContents
End If
Next xLigne
Next xColonne
End Sub


Sub AvoirNeufNombres()
For Carré = 1 To 9
SudokuNombre(Carré) = Int(Rnd() * 9) + 1
If Carré > 1 Then
Do
OuiNon = True
For m = 1 To Carré - 1
If SudokuNombre(Carré) = SudokuNombre(m) Then
SudokuNombre(Carré) = Int(Rnd() * 9) + 1
OuiNon = False
Exit For
End If
Next m
Loop Until OuiNon
End If
Next Carré
End Sub


Sub AvoirBoiteRef()
BoiteRef(1) = Range("TopCarré").Address
BoiteRef(2) = Range("TopCarré").Offset(0, 3).Address
BoiteRef(3) = Range("TopCarré").Offset(0, 6).Address
BoiteRef(4) = Range("TopCarré").Offset(3, 0).Address
BoiteRef(5) = Range("TopCarré").Offset(3, 3).Address
BoiteRef(6) = Range("TopCarré").Offset(3, 6).Address
BoiteRef(7) = Range("TopCarré").Offset(6, 0).Address
BoiteRef(8) = Range("TopCarré").Offset(6, 3).Address
BoiteRef(9) = Range("TopCarré").Offset(6, 6).Address
End Sub
Sub LigneHazard()
For x = 1 To 3
LigneMix(x) = Int(Rnd() * 3) + 1
If x > 1 Then
Do
OuiNon = True
For y = 1 To x - 1
If LigneMix(x) = LigneMix(y) Then
LigneMix(x) = Int(Rnd() * 3) + 1
OuiNon = False
Exit For
End If
Next y
Loop Until OuiNon
End If
Next x
End Sub


Sub ColonneHazard()
For x = 1 To 3
ColonneMix(x) = Int(Rnd() * 3) + 1
If x > 1 Then
Do
OuiNon = True
For y = 1 To x - 1
If ColonneMix(x) = ColonneMix(y) Then
ColonneMix(x) = Int(Rnd() * 3) + 1
OuiNon = False
Exit For
End If
Next y
Loop Until OuiNon
End If
Next x
End Sub


Sub GenererPuzzle()
EffacerTout
Application.ScreenUpdating = False
Do
MettreDansGrille
OuiNon = True
For n = 0 To 8
For x = 0 To 8
If IsEmpty(Range("TopCarré").Offset(n, x)) Then
OuiNon = False
Exit For
End If
Next x
If OuiNon = False Then Exit For
Next n
Loop Until OuiNon
CréePuzzle
End Sub


Sub MettreDansGrille()

Range("Grid").ClearContents
AvoirNeufNombres
AvoirBoiteRef
For n = 1 To 9

For Carré = 1 To 9
Place = False
For xColonne = 1 To 3
For xLigne = 1 To 3
VerifieColonne
VerifieLigne
If IsEmpty(Range(BoiteRef(Carré)).Offset(LigneMix(xLigne) - 1, ColonneMix(xColonne) - 1).Value) Then
If LigneOK And ColonneOK Then
Range(BoiteRef(Carré)).Offset(LigneMix(xLigne) - 1, ColonneMix(xColonne) - 1).Value = SudokuNombre(n)
Place = True
Exit For
End If
End If
Next xLigne
If Place Then Exit For
Next xColonne
If Not Place Then Exit Sub
Next Carré
Next n
End Sub


Sub VerifieColonne()
For x = 1 To 9
If Range("TopCarré").Offset(x - 1, Range(BoiteRef(Carré)).Column - Range("TopCarré").Column + ColumnMix(xColonne) - 1).Value = SudokuNombre(n) Then
ColonneOK = False
Exit Sub
End If
Next x
ColonneOK = True
End Sub


Sub VerifieLigne()
For x = 1 To 9
If Range("TopCarré").Offset(Range(BoiteRef(Carré)).Row - Range("Topcarré").Row + RowMix(xLigne) - 1, x - 1).Value = SudokuNombre(n) Then
LigneOK = False
Exit Sub
End If
Next x
LigneOK = True
End Sub


Sub CréePuzzle()
For PositionJeux = 1 To 1000
n = Int(Rnd * 9)
x = Int(Rnd * 9)
If Not IsEmpty(Range("TopCarré").Offset(n, x)) Then
SudokuNombre(1) = Range("TopCarré").Offset(n, x).Value
OuiNon = True
Select Case n
Case 0
TrouverDansLigne (Range("TopCarré").Row + 1)
TrouverDansLigne (Range("TopCarré").Row + 2)
Case 1
TrouverDansLigne (Range("TopCarré").Row)
TrouverDansLigne (Range("TopCarré").Row + 2)
Case 2
TrouverDansLigne (Range("TopCarré").Row)
TrouverDansLigne (Range("TopCarré").Row + 1)
Case 3
TrouverDansLigne (Range("TopCarré").Row + 4)
TrouverDansLigne (Range("TopCarré").Row + 5)
Case 4
TrouverDansLigne (Range("TopCarré").Row + 3)
TrouverDansLigne (Range("TopCarré").Row + 5)
Case 5
TrouverDansLigne (Range("TopCarré").Row + 3)
TrouverDansLigne (Range("TopCarré").Row + 4)
Case 6
TrouverDansLigne (Range("TopCarré").Row + 7)
TrouverDansLigne (Range("TopCarré").Row + 8)
Case 7
TrouverDansLigne (Range("TopCarré").Row + 6)
TrouverDansLigne (Range("TopCarré").Row + 8)
Case 8
TrouverDansLigne (Range("TopCarré").Row + 6)
TrouverDansLigne (Range("TopCarré").Row + 7)
End Select
Select Case x
Case 0
TrouverDansColonne (Range("TopCarré").Column + 1)
TrouverDansColonne (Range("TopCarré").Column + 2)
Case 1
TrouverDansColonne (Range("TopCarré").Column)
TrouverDansColonne (Range("TopCarré").Column + 2)
Case 2
TrouverDansColonne (Range("TopCarré").Column)
TrouverDansColonne (Range("TopCarré").Column + 1)
Case 3
TrouverDansColonne (Range("TopCarré").Column + 4)
TrouverDansColonne (Range("TopCarré").Column + 5)
Case 4
TrouverDansColonne (Range("TopCarré").Column + 3)
TrouverDansColonne (Range("TopCarré").Column + 5)
Case 5
TrouverDansColonne (Range("TopCarré").Column + 3)
TrouverDansColonne (Range("TopCarré").Column + 4)
Case 6
TrouverDansColonne (Range("TopCarré").Column + 7)
TrouverDansColonne (Range("TopCarré").Column + 8)
Case 7
TrouverDansColonne (Range("TopCarré").Column + 6)
TrouverDansColonne (Range("TopCarré").Column + 8)
Case 8
TrouverDansColonne (Range("TopCarré").Column + 6)
TrouverDansColonne (Range("TopCarré").Column + 7)
End Select
If OuiNon Then
Range("TopCarré").Offset(n, x).ClearContents
Range("TopCarré").Offset(n, x).Font.ColorIndex = 3
End If
End If
Next PositionJeux
End Sub


Sub TrouverDansLigne(xLigne As Byte)
If Not IsEmpty(Range("TopCarré").Offset(xLigne - Range("TopCarré").Row, x)) Then Exit Sub
For xColonne = 0 To 8
If Range("TopCarré").Offset(xLigne - Range("TopCarré").Row, xColonne).Value = SudokuNombre(1) Then
Exit Sub
End If
Next xColonne
OuiNon = False
End Sub


Sub TrouverDansColonne(xColonne As Byte)
If Not IsEmpty(Range("TopCarré").Offset(n, xColonne - Range("TopCarré").Column)) Then Exit Sub
For xLigne = 0 To 8
If Range("TopCarré").Offset(xLigne, xColonne - Range("TopCarré").Column).Value = SudokuNombre(1) Then
Exit Sub
End If
Next xLigne
OuiNon = False
End Sub

MODULE 2

Sub RésoudreTout()
Do
Tjrsolution = False
ScruterGrille
ScruterGrille
Loop Until Not Tjrsolution
End Sub


Sub ScruterGrille()
'permet d'assurer que la référence des cellules dans les boîte soit toujours établi
AvoirBoiteRef
'Boucle pour la grille entière
For xLigne = 0 To 8
For xColonne = 0 To 8
If IsEmpty(Range("TopCarré").Offset(xLigne, xColonne)) Then
'Boucle pour les nombres compris entre 1 et 9
For x = 1 To 9
'Le nombre du premier contrôle peut-être mis dan Ligne/Colonne/Carré.
OuiNon = True
PlaceNombreDansLigne
If OuiNon Then
OuiNon = True
PlaceNombreDansColonne
If OuiNon Then
OuiNon = True
PlaceNombreDansCarré
If OuiNon Then
'permet de vérifier si les autres espaces de la boîte ne sont pas employées
Jouer = 0
If Range(BoiteRef(Carré)).Address <> Range("TopCarré").Offset(xLigne, xColonne).Address Then
If IsEmpty(Range(BoiteRef(Carré))) Then VerifieCarré 0, 0
End If
If Range(BoiteRef(Carré)).Offset(0, 1).Address <> Range("TopCarré").Offset(xLigne, xColonne).Address Then
If IsEmpty(Range(BoiteRef(Carré)).Offset(0, 1)) Then VerifieCarré 0, 1
End If
If Range(BoiteRef(Carré)).Offset(0, 2).Address <> Range("TopCarré").Offset(xLigne, xColonne).Address Then
If IsEmpty(Range(BoiteRef(Carré)).Offset(0, 2)) Then VerifieCarré 0, 2
End If
If Range(BoiteRef(Carré)).Offset(1, 0).Address <> Range("TopCarré").Offset(xLigne, xColonne).Address Then
If IsEmpty(Range(BoiteRef(Carré)).Offset(1, 0)) Then VerifieCarré 1, 0
End If
If Range(BoiteRef(Carré)).Offset(1, 1).Address <> Range("TopCarré").Offset(xLigne, xColonne).Address Then
If IsEmpty(Range(BoiteRef(Carré)).Offset(1, 1)) Then VerifieCarré 1, 1
End If
If Range(BoiteRef(Carré)).Offset(1, 2).Address <> Range("TopCarré").Offset(xLigne, xColonne).Address Then
If IsEmpty(Range(BoiteRef(Carré)).Offset(1, 2)) Then VerifieCarré 1, 2
End If
If Range(BoiteRef(Carré)).Offset(2, 0).Address <> Range("TopCarré").Offset(xLigne, xColonne).Address Then
If IsEmpty(Range(BoiteRef(Carré)).Offset(2, 0)) Then VerifieCarré 2, 0
End If
If Range(BoiteRef(Carré)).Offset(2, 1).Address <> Range("TopCarré").Offset(xLigne, xColonne).Address Then
If IsEmpty(Range(BoiteRef(Carré)).Offset(2, 1)) Then VerifieCarré 2, 1
End If
If Range(BoiteRef(Carré)).Offset(2, 2).Address <> Range("TopCarré").Offset(xLigne, xColonne).Address Then
If IsEmpty(Range(BoiteRef(Carré)).Offset(2, 2)) Then VerifieCarré 2, 2
End If
If Jouer <> 0 Then
CompteurRempliDansLigne
CompteurRempliDansColonne
End
If Jouer = 0 Then
Range("TopCarré").Offset(xLigne, xColonne).Value = x
Range("TopCarré").Offset(xLigne, xColonne).Font.ColorIndex = 5
StillSolving = True
Exit Sub
End If
End If
End If
End If
Next x
End If
Next xColonne
Next xLigne
End Sub


Sub CompteurRempliDansLigne()
Compteur = 0
For n = 0 To 8
If Not IsEmpty(Range("TopCarré").Offset(xLigne, n)) Then
Compteur = Compteur + 1
End If
Next n If Compteur 8 Then Jouer 0
End Sub


Sub CompteurRempliDansColonne()
Compteur = 0
For n = 0 To 8
If Not IsEmpty(Range("TopCarré").Offset(n, xColonne)) Then
Compteur = Compteur + 1
End If
Next n If Compteur 8 Then Jouer 0
End Sub


Sub PlaceNombreDansLigne()
For n = 0 To 8
If Range("TopCarré").Offset(xLigne, n).Value = x Then
OuiNon = False
Place = True
Exit Sub
End If
Next n
End Sub


Sub PlaceNombreDansColonne()
For n = 0 To 8
If Range("TopCarré").Offset(n, xColonne).Value = x Then
OuiNon = False
Exit Sub
End If
Next n
End Sub


Sub PlaceNombreDansCarré()
' permet de découvrir dans quelle place nous sommes
Select Case xLigne
Case 0, 1, 2
GrandCarréLigne = 1
Case 3, 4, 5
GrandCarréLigne = 2
Case 6, 7, 8
GrandCarréLigne = 3
End Select
Select Case xColonne
Case 0, 1, 2
GrandCarréColonne = 1
Case 3, 4, 5
GrandCarréColonne = 2
Case 6, 7, 8
GrandCarréColonne = 3
End Select
Select Case GrandCarréLigne
Case 1
Select Case GrandCarréColonne
Case 1
Carré = 1
Case 2
Carré = 2
Case 3
Carré = 3
End Select
Case 2
Select Case GrandCarréColonne
Case 1
Carré = 4
Case 2
Carré = 5
Case 3
Carré = 6
End Select
Case 3
Select Case GrandCarréColonne
Case 1
Carré = 7
Case 2
Carré = 8
Case 3
Carré = 9
End Select
End Select
'vérifie chaque place pour écrire une boucle
If Range(BoiteRef(Carré)).Value = x Then
OuiNon = False
Exit Sub
End If
If Range(BoiteRef(Carré)).Offset(1, 0).Value = x Then
OuiNon = False
Exit Sub
End If
If Range(BoiteRef(Carré)).Offset(2, 0).Value = x Then
OuiNon = False
Exit Sub
End If
If Range(BoiteRef(Carré)).Offset(0, 1).Value = x Then
OuiNon = False
Exit Sub
End If
If Range(BoiteRef(Carré)).Offset(1, 1).Value = x Then
OuiNon = False
Exit Sub
End If
If Range(BoiteRef(Carré)).Offset(2, 1).Value = x Then
OuiNon = False
Exit Sub
End If
If Range(BoiteRef(Carré)).Offset(0, 2).Value = x Then
OuiNon = False
Exit Sub
End If
If Range(BoiteRef(Carré)).Offset(1, 2).Value = x Then
OuiNon = False
Exit Sub
End If
If Range(BoiteRef(Carré)).Offset(2, 2).Value = x Then
OuiNon = False
Exit Sub
End If
End Sub


Sub ExamineLigne(xLigne As Byte)
If Not IsEmpty(Range("TopCarré").Offset(xLigne, xColonne)) Then
OuiNon = False
Exit Sub
End If
For n = 0 To 8
If Range("TopCarré").Offset(xLigne, n) = x Then
OuiNon = False
Exit Sub
End If
Next n
End Sub


Sub ExamineColonne(xColonne As Byte)
If Not IsEmpty(Range("TopCarré").Offset(xLigne, xColonne)) Then
OuiNon = False
Exit Sub
End If
For n = 0 To 8
If Range("TopCarré").Offset(n, xColonne) = x Then
OuiNon = False
Exit Sub
End If
Next n
End Sub


Sub VerifieCarré(xLigne As Byte, xColonne As Byte)
For n = 0 To 8

Select Case Carré
Case 1, 2, 3
If Range("TopCarré").Offset(xLigne, n).Value = x Then Exit Sub
Case 4, 5, 6
If Range("TopCarré").Offset(xLigne + 3, n).Value = x Then Exit Sub
Case 7, 8, 9
If Range("TopCarré").Offset(xLigne + 6, n).Value = x Then Exit Sub
End Select
Select Case Carré
Case 1, 4, 7
If Range("TopCarré").Offset(n, xColonne).Value = x Then Exit Sub
Case 2, 5, 8
If Range("TopCarré").Offset(n, xColonne + 3).Value = x Then Exit Sub
Case 3, 6, 9
If Range("TopCarré").Offset(n, xColonne + 6).Value = x Then Exit Sub
End Select
Next n
Jouer = Jouer + 1
End Sub
0

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

Posez votre question
tiago27400 Messages postés 7 Date d'inscription jeudi 23 février 2006 Statut Membre Dernière intervention 15 avril 2006
13 avril 2006 à 21:06
Merci Kenji, je vais essayer de suivre tes conseils !
0
tiago27400 Messages postés 7 Date d'inscription jeudi 23 février 2006 Statut Membre Dernière intervention 15 avril 2006
13 avril 2006 à 21:57
Vous aviez tous raisons et Merci pour vos conseils, le problème venait bien de ma variable TopCarré sauf que désormais après avoir effectué les modifications je bloque à ce niveau :

Sub VerifieColonne()
For x = 1 To 9
If Range("B5:J13").Offset(x - 1, Range(BoiteRef(Carré)).Column - Range("B5:J13").Column + ColonneMix(xColonne) - 1).Value = SudokuNombre(n) Then

Que signifie erreur d'execution 13 ??
0
Utilisateur anonyme
13 avril 2006 à 22:19
Est-tu sur de ton BoiteRef(Carré) ? Il dois être de la forme "colonne+ligne" ou "colonne+ligne:colonne+ligne".

Kenji


<HR width="100%" SIZE=2>


Merci de cliquer sur "Réponse acceptée" si une réponse vous convient.
0
tiago27400 Messages postés 7 Date d'inscription jeudi 23 février 2006 Statut Membre Dernière intervention 15 avril 2006
13 avril 2006 à 22:41
Je ne pense pas que le problème vient de la kenji
0
Utilisateur anonyme
13 avril 2006 à 22:50
Tu le pense, mais l'as tu vérifier ? Pour celà décompose ta condition, fait du pas-à-pas et vérifie si chaque therme est du bon type.

Kenji

<HR width="100%" SIZE=2>


Merci de cliquer sur "Réponse acceptée" si une réponse vous convient.
0
tiago27400 Messages postés 7 Date d'inscription jeudi 23 février 2006 Statut Membre Dernière intervention 15 avril 2006
15 avril 2006 à 23:17
j'ai une petite question d'ordre technique, qui je l'espère pour l'un d'entre vous, paraitra candide : Une variable peut-elle ètre déclaré ailleurs que dans les modules, les modules de classe ou l'userform d'un programme ?
Toute réponse est la bienvenue !!
MERCIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
0
tiago27400 Messages postés 7 Date d'inscription jeudi 23 février 2006 Statut Membre Dernière intervention 15 avril 2006
15 avril 2006 à 23:41
Ou en d'autre terme pour être plus explicite si j'ai dans une procédure :

.....Range ( " kkchoz " ), ce kkchoz peut-il etre défini en dehors des modules ? Sur la feuille de calcul ? De quel manière ?

Merci pour toute précision.
0
rvblog Messages postés 792 Date d'inscription vendredi 4 mars 2005 Statut Membre Dernière intervention 12 juin 2012 7
17 avril 2006 à 03:16
Salut tiago27400, salut à tous,

oui, par exemple, en nommant des plages :

- Fais une sélection de cellules quelconques
- Menu Insertion>>Noms>>Définir.
- et tu la nommes (c'est une déclaration).

dans ton cas, si kkchos est entre guillemets (ce n'est d'ailleurs pas une variable, mais une constante), et que ce n'est pas une valeur d'adresse syntaxiquement correcte, c'est une plage nommée (ou une plage inexistante, mais ça, c'est ton problème).
tu peux aussi y accéder (par défaut) à gauche de la barre de formules (Fx), il y a une combobox (infobulle Zone Nom).

à+

rvblogn<SUP>
</SUP><SUP>Je veux ton bien... et je l'aurais... mais jamais avant la page 4
</SUP>
0
Rejoignez-nous