Probleme if / elseif

Bonjour à toutes et tous,

Cela fait un moment que je ne suis pas venu sur le forum mais aujourd'hui je viens de m'apercevoir d'un problème de codage lorsque je tente de compléter des fichiers générés depuis ma base.

ne trouvant pas la soluce je m'en remet à vos expériences

Mon soucis c'est entre

If (Project_Staff_Status = "PP") Then

et

ElseIf (Project_Staff_Status = "PnP") Then

seul le if est interprété pas le elseif

si j'inverse les PP et PNP cela fonctionnera aussi mais que pour le 1er if donc le problème réside bien dans le codage du if / elseif

pour information le count_wp renvoi un nombre

si count_wp >0 alors il peut compléter le fichier généré

Seulement voila j'ai une variable

Project_Staff_Status

qui peut prendre comme valeur PP ou PNP (les informations ne vont pas dans les mêmes cellules)

une idée avec le code suivant car il me serait trop compliqué de généré un fichier test?

If IsEmpty(WP_array) Then
 count_wp = "0"
Else
count_wp = WP_array.Rows.Count
End If

If count_wp <> "0" Then

If (Project_Staff_Status = "PP") Then
If (count_wp >= 1) Then
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("I27") = WP_array.Cells(1, 3)
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("H27") = WP_array.Cells(1, 4)
End If

If (count_wp >= 2) Then
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("I28") = WP_array.Cells(2, 3)
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("H28") = WP_array.Cells(2, 4)
End If

If (count_wp >= 3) Then
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("I29") = WP_array.Cells(3, 3)
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("H29") = WP_array.Cells(3, 4)
End If

If (count_wp >= 4) Then
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("I30") = WP_array.Cells(4, 3)
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("H30") = WP_array.Cells(4, 4)
End If

If (count_wp >= 5) Then
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("I31") = WP_array.Cells(5, 3)
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("H31") = WP_array.Cells(5, 4)
End If

If (count_wp >= 6) Then
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("I32") = WP_array.Cells(6, 3)
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("H32") = WP_array.Cells(6, 4)
End If

If (count_wp >= 7) Then
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("I33") = WP_array.Cells(7, 3)
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("H33") = WP_array.Cells(7, 4)
End If

If (count_wp >= 8) Then
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("I34") = WP_array.Cells(8, 3)
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("H34") = WP_array.Cells(8, 4)
End If

If (count_wp >= 9) Then
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("I35") = WP_array.Cells(9, 3)
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("H35") = WP_array.Cells(9, 4)
End If

If (count_wp >= 10) Then
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("I36") = WP_array.Cells(10, 3)
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("H36") = WP_array.Cells(10, 4)
End If

ElseIf (Project_Staff_Status = "PnP") Then

If (count_wp >= 1) Then
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("K28") = WP_array.Cells(1, 3)
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("J28") = WP_array.Cells(1, 4)
End If

If (count_wp >= 2) Then
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("K29") = WP_array.Cells(2, 3)
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("J29") = WP_array.Cells(2, 4)
End If

If (count_wp >= 3) Then
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("K30") = WP_array.Cells(3, 3)
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("J30") = WP_array.Cells(3, 4)
End If

If (count_wp >= 4) Then
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("K31") = WP_array.Cells(4, 3)
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("J31") = WP_array.Cells(4, 4)
End If

If (count_wp >= 5) Then
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("K32") = WP_array.Cells(5, 3)
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("J32") = WP_array.Cells(5, 4)
End If

If (count_wp >= 6) Then
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("K33") = WP_array.Cells(6, 3)
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("J33") = WP_array.Cells(6, 4)
End If

If (count_wp >= 7) Then
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("K34") = WP_array.Cells(7, 3)
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("J34") = WP_array.Cells(7, 4)
End If

If (count_wp >= 8) Then
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("K35") = WP_array.Cells(8, 3)
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("J35") = WP_array.Cells(8, 4)
End If

If (count_wp >= 9) Then
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("K36") = WP_array.Cells(9, 3)
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("J36") = WP_array.Cells(9, 4)
End If

If (count_wp >= 10) Then
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("K37") = WP_array.Cells(10, 3)
Workbooks(Timesheet_Empty).Worksheets("Projet").Range("J37") = WP_array.Cells(10, 4)
End If

End If
Else:
End If
End If

merci par avance pour votre aide

Hello,

Bon déjà on peut simplifier un peu le code ce sera plus simple à lire :

If IsEmpty(WP_array) Then
     count_wp = "0"
Else
    count_wp = WP_array.Rows.Count
End If

If count_wp <> "0" Then

    If Project_Staff_Status = "PP" Then

        For i = 1 To 10
            If (count_wp >= i) Then

                Workbooks(Timesheet_Empty).Worksheets("Projet").Range("I" & 26 + i) = WP_array.Cells(i, 3)
                Workbooks(Timesheet_Empty).Worksheets("Projet").Range("H" & 26 + i) = WP_array.Cells(i, 4)

            End If
        Next i

    ElseIf Project_Staff_Status = "PnP" Then

        For i = 1 To 10
            If (count_wp >= i) Then

                Workbooks(Timesheet_Empty).Worksheets("Projet").Range("K" & 27 + i) = WP_array.Cells(i, 3)
                Workbooks(Timesheet_Empty).Worksheets("Projet").Range("J" & 27 + i) = WP_array.Cells(i, 4)

            End If
        Next i

    End If
Else

End If
End If

Moi ce qui me chagrine, c'est le dernier End if, quand tu regardes l'indentation il ne devrait pas être là...

Il y a un autre if plus haut dans ton code qui l'expliquerait ?

merci à vous pour cette optimalisation qui en plus m'aura permis de me mettre sur la bonne voie pour trouver la soluce :)

Hello du coup c'était lié à quoi ? :)

au endif de fin comme suggéré mais aussi à un else à la fin :)

Rechercher des sujets similaires à "probleme elseif"