Macro à plusieurs conditions

benjack

XLDnaute Nouveau
Bonjour à tous

je prépare une macro d'impression un peu particulière.
je veux imprimer des feuilles suivant ce qu'on coche dans un formulaire user form
autrement dis je met des cases à cocher au choix ( case1; case2;case3), (il est possible d'en sélectionner plusieurs) et en fonction de ce qu'on coche bah je choisi mon imprimante ça imprime direct.

je bloque juste sur les conditions ! il me sort "compil error, else without if"

Si quelqu'un peut me sauver de cette situation ....!:)

Else: If CheckBox1 = True Then If Application.Dialogs(xlDialogPrinterSetup).Show = False Then Exit Sub
Sheets("Sheet1").PrintOut

Else: If CheckBox1 = True And CheckBox2 = True Then If Application.Dialogs(xlDialogPrinterSetup).Show = False Then Exit Sub
Sheets("Sheet1").PrintOut
Sheets("Sheet2").PrintOut

Else: If CheckBox1 = True And CheckBox2 = True And CheckBox3 = True Then If Application.Dialogs(xlDialogPrinterSetup).Show = False Then Exit Sub
Sheets("Sheet1").PrintOut
Sheets("Sheet2").PrintOut
Sheets("Sheet3").PrintOut

Else: If CheckBox1 = True And CheckBox3 = True Then If Application.Dialogs(xlDialogPrinterSetup).Show = False Then Exit Sub
Sheets("Sheet1").PrintOut
Sheets("Sheet3").PrintOut

Else: If CheckBox2 = True Then If Application.Dialogs(xlDialogPrinterSetup).Show = False Then Exit Sub
Sheets("Sheet2").PrintOut

Else: If CheckBox3 = True Then If Application.Dialogs(xlDialogPrinterSetup).Show = False Then Exit Sub
Sheets("Sheet3").PrintOut

End If



Merci bien !

Ben
 

Softmama

XLDnaute Accro
Re : Macro à plusieurs conditions

bonjour,

Le if...elseif...end if fonctionne de la façon suivante :
Commencer par une condition:
VB:
If Condition then
  'le code qui va  bien
ElseIf Condition2 then
  ' le code qui va pour la condition2
ElseIf Condition3 then
  ' le code qui va pour la condition3
  ' à répéter autant de fois que nécessaire
End If
 

Discussions similaires

Statistiques des forums

Discussions
312 520
Messages
2 089 272
Membres
104 083
dernier inscrit
hecko