For loop that does not run without giving any error too

1

I've done a test with this Sub but when I compile, it does not do anything. Also, it does not give any errors. Then I do not know how to compile it.

Can you help me?

Public Sub calculerScore()

Dim colonne, ligne, ligne_referencej, colonne_reference, score_reponse As Integer

colonne = 1
ligne = 1
ligne_reference = 1
colonne_reference = 1
For colonne = 1 To colonne = 8
    For ligne = 1 To ligne = 8
        If Cells(ligne, colonne).Value >= Cells(ligne_reference, colonne_reference).Value Then
            Cells(ligne + 10, colonne + 10).Value = 1
        Else
            Cells(ligne + 10, colonne + 10).Value = 0
        End If
        Next ligne
        ligne_reference = ligne_reference + 1
    Next colonne
colonne_reference = colonne_reference + 1
End Sub
    
asked by ThePassenger 04.01.2017 в 18:51
source

2 answers

2

It seems that your error is in the following lines:

For colonne = 1 To colonne = 8
    For ligne = 1 To ligne = 8

After the To , when you put colonne = 8 and ligne = 8 , what you do is assign the value to the variable, you're telling the compiler to iterate this variable from 1 to 8, or wait says the compiler here is already putting the value of 8 colonne = 8 , it is already 8, then the cycle ends For

To fix your detail you just have to remove the assignment, leave the value 8 alone.

It is worth mentioning that the code compiles keywords , although it does not do what you expect, but compiles because you can put an assignment in that part of the cycle for , by putting the assignment in runtime first assign value to the variable then take the variable as what a value is, with the new value it already has.

Example:

I can have the variables inicio = 0 and the variable fin = 10 :

for i = inicio To fin

that would be equivalent to having

for i= inicio to fin = 10

or

for i = 0 to 10

Greetings.

    
answered by 04.01.2017 / 19:57
source
2

Change your code for this, detail that you change the instructions For :

Public Sub calculerScore()

Dim colonne, ligne, ligne_referencej, colonne_reference, score_reponse As Integer

colonne = 1
ligne = 1
ligne_reference = 1
colonne_reference = 1
For colonne = 1 To 8
    For ligne = 1 To 8
        If Cells(ligne, colonne).Value >= Cells(ligne_reference, colonne_reference).Value Then
            Cells(ligne + 10, colonne + 10).Value = 1
        Else
            Cells(ligne + 10, colonne + 10).Value = 0
        End If
        Next ligne
        ligne_reference = ligne_reference + 1
    Next colonne
colonne_reference = colonne_reference + 1
End Sub
    
answered by 04.01.2017 в 19:20