My loop doesn't end

karltlbm

New Member
Joined
Jun 3, 2015
Messages
10
Hello, 2nd post here.

I have this code :

Code:
Sub creer_tache()

Dim nom_liaison_tache As Variant
Dim nom_projet_liaison_tache As Variant
Dim check_P As Boolean
Dim check_ssp As Boolean


check_P = False
check_ssp = False


Dim i As Integer
For i = 1 To 20


    nom_projet_liaison_tache = InputBox("dans quel projet se trouve cette tache ?", "LIAISON")
    
    'Si le projet est trouvé
    If nom_projet_liaison_tache = List_Projet(i).nom_P Then
        
        check_P = True
        Sheets(nom_projet_liaison_tache).Select
        nom_liaison_tache = InputBox("Avec quel sous-projet cette tache est liée ?", "LIAISON")
        
        Dim j As Integer
        For j = 1 To 20
        
            'Si le ssp est trouvé
            If nom_liaison_tache = List_SSP(j).nom_ssp Then
                
                check_ssp = True
                Range(nom_liaison_tache).Select
            
            End If
            
                Dim indice As Integer
                indice = 0
                    
                'Tant que la cellule est occupée
                Do While ActiveCell.Offset(indice, 0).Value <> Empty
                    
                    indice = indice + 1
                
                Loop
                
                Range(ActiveCell.Offset(1, 0), ActiveCell.Offset(indice + 1, 7)).Select
                Selection.Cut
                ActiveCell.Offset(1, 0).Select
                ActiveSheet.Paste
                ActiveCell.Offset(-1, 0).Select
                        
                'NOM
                List_tache(id_tache).nom_tache = InputBox("nom de cette tache ?")
                ActiveCell.Offset(0, 0).Value = List_tache(id_tache).nom_tache
                
                'ID
                List_tache(id_tache).id_tache = InputBox("id de cette tache ?")
                ActiveCell.Offset(0, 1).Value = List_tache(id_tache).id_tache
                
                'DEADLINE
                List_tache(id_tache).deadline_tache = InputBox("deadline de cette tache ?")
                ActiveCell.Offset(0, 2).Value = List_tache(id_tache).deadline_tache
    
                'STATUT
                List_tache(id_tache).statut_tache = InputBox("statut de cette tache ?")
                ActiveCell.Offset(0, 3).Value = List_tache(id_tache).statut_tache
                
                'DEBUT
                List_tache(id_tache).date_debut_tache = InputBox("Début de cette tache ?")
                ActiveCell.Offset(0, 4).Value = List_tache(id_tache).date_debut_tache
                
                'FIN
                List_tache(id_tache).date_fin_tache = InputBox("Fin de cette tache ?")
                ActiveCell.Offset(0, 5).Value = List_tache(id_tache).date_fin_tache
                
                'COUT PREV
                List_tache(id_tache).cout_prev_tache = InputBox("cout prev de cette tache ?")
                ActiveCell.Offset(0, 6).Value = List_tache(id_tache).cout_prev_tache
                
                'COUT REEL
                List_tache(id_tache).cout_reel_tache = InputBox("Cout réel de cette tache ?")
                ActiveCell.Offset(0, 7).Value = List_tache(id_tache).cout_reel_tache
                
                'On nomme la ligne par le nom du ssp
                Range(ActiveCell, ActiveCell.Offset(0, 7)).Select
            
                ActiveWorkbook.Names.Add Name:=List_tache(id_tache).nom_tache, RefersToR1C1:= _
                "=test!R6C4:R6C11"
                    
                Exit For
                Exit For
            
            Next j
    
    End If
        
Next i
    
If check_P = False Then
    
    MsgBox ("Il n'y a pas de projet de ce nom")
        
End If
    
If check_ssp = False Then

    MsgBox ("il n'y a pas de ssp de ce nom")
        
End If


End Sub

I think i got a little bit lost because my loop doesn't end. Excel keeps on asking me to fill the first inputbox even if i've already done it. It seems that my 2 Exit for are useless.

If you see what's wrong please tell me :)

Thank you
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi,

I can't tell what some of your object are, for example: List_Projet(i).nom_P

However, I suspect that your InputBox statement needs to be outside the loop because what is happening now is:

Set i = 1
Input Project
Check against List_Projet(1).nom_P

Set i = 2
Input Project
Check against List_Projet(2).nom_P

Set i = 3
Input Project
Check against List_Projet(3).nom_P

etc

So move the inputbox statement before the "For i = 1 To 20" statement.
 
Upvote 0

Forum statistics

Threads
1,214,915
Messages
6,122,212
Members
449,074
Latest member
cancansova

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top