Conditions if et else

bonjour, j’ai une macro ci-joint, avec deux conditions et instructions pour chacunes d’entre elles. Mon problème est que la réponse oui et non ce mélange malgré l’utilisation du else. Je sais que je l’ai mal utiliser mais je ne vois pas comment faire …

merci de votre aide !

Sub partie_5()

MsgBox « quitter », vbInformation + vbYesNo, « mon programme »
If reponse = « oui » Then MsgBox « Au revoir ! »
Application.Quit

else
If reponse = « non » Then MsgBox « on continue alors ? », vbQuestion

For i = 1 To 13
For ni = 1 To 6

Cells(i, ni).Borders.Value = 1
Cells(1, ni).Interior.ColorIndex = 6

Next
Next

Range(« A1 »).FormulaR1C1 = « Civilité »
Range(« B1 »).FormulaR1C1 = « Nom »
Range(« C1 »).FormulaR1C1 = « Prénom »
Range(« D1 »).FormulaR1C1 = « Adresse »
Range(« E1 »).FormulaR1C1 = « Lieu »
Range(« F1 »).FormulaR1C1 = « Pays »

Range(« A1:F1 »).Select

With Selection

          .HorizontalAlignment = xlCenter
          .Font.Name = "Time roman"
          .Font.Size = 12

Range(« A2 »).Select

End With

End Sub

Bonjour,

Comme ça :

Option Explicit
Sub partie_5()
Dim reponse As Integer
Dim i As Integer
Dim ni As Integer

  reponse = MsgBox("quitter", vbInformation + vbYesNo, "mon programme")
  If reponse = vbYes Then
    MsgBox "Au revoir !"
  ElseIf reponse = vbNo Then
    MsgBox "on continue alors ?", vbQuestion
    With ActiveSheet
      For i = 1 To 13
        For ni = 1 To 6
          .Cells(i, ni).Borders.Value = 1
          .Cells(1, ni).Interior.ColorIndex = 6
        Next
      Next
      .Range("A1").Formula = "Civilité"
      .Range("B1").Formula = "Nom"
      .Range("C1").Formula = "Prénom"
      .Range("D1").Formula = "Adresse"
      .Range("E1").Formula = "Lieu"
      .Range("F1").Formula = "Pays"
      With .Range("A1:F1")
        .HorizontalAlignment = xlCenter
        .Font.Name = "Time roman"
        .Font.Size = 12
      End With
      .Range("A2").Select
    End With
  End If
  
End Sub

Notes que tu peux remplacer :

  ElseIf reponse = vbNo Then

Par simplement

  Else

Vu qu’il n’y a que 2 boutons dans ton msgBox, donc si c’est pas oui, c’est non.

Ce sujet a été automatiquement fermé après 30 jours. Aucune réponse n’est permise dorénavant.