Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Excel > Macros et VBA Excel
Macros et VBA Excel Vos questions relatives aux macros Excel, à l'utilisation de VBA et à l'automatisation de vos classeurs Excel.
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 26/08/2011, 14h30   #1
Invité de passage
 
Femme
Inscription : août 2011
Messages : 10
Détails du profil
Informations personnelles :
Sexe : Femme

Informations forums :
Inscription : août 2011
Messages : 10
Points : 0
Points : 0
Par défaut IF imbriqués pour les nuls

Bonjour à tous,

Ayant un soucis avec ce code, je teste le contenu d'une cellule, j'aimerai dans le cas ou cette cellule contient le contenu recherché, exécute un autre IF, sinon exécute un autre IF.

Je précise que le contenu de mon code est fait par la génératrice VBA d'excel.

D'avance, merci.

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
Sub Macro9()
'
' Macro9 Macro
'
 
'
 
If Cells(1, 4).Value = "SPONTANEE" Then
 
 
If MsgBox("Opération irréversible. Souhaitez-vous continuez ?", vbQuestion + vbYesNo, "QUESTION ...") = vbYes Then
 
    nom = Format(Date, "yyyy-mm-dd") & "   " & Format(Time, "hh-mm") & "   " & " SPONTANEE " & ActiveWorkbook.Name
    ActiveWorkbook.SaveCopyAs ActiveWorkbook.Path & "\" & nom
    rep = MsgBox("Votre commande spontannée est sauvegardée sous le nom :" & vbCrLf & vbCrLf & " " & nom, vbYes + vbInformation, "Copie sauvegarde commande")
 
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
    IgnorePrintAreas:=False
    Range("A5:H1000").Select
    Selection.ClearContents
 
    Range("J3").Select
    ActiveCell.FormulaR1C1 = "CLOTUREE"
 
 
 
    Range("A5").Select
 
    ThisWorkbook.Close SaveChanges:=False
MsgBox (" Commande spontannée sauvegardée. Fermeture d'excel.")
Application.Quit
 
    Else
 
 
 
Else
 
 
If MsgBox("Attention ! Opération irréversible." & vbCrLf & vbCrLf & "Souhaitez-vous clôturer la commande ?", vbQuestion + vbYesNo, "QUESTION ...") = vbYes Then
 
    nom = Format(Date, "yyyy-mm-dd") & "   " & Format(Time, "hh-mm") & "   " & ActiveWorkbook.Name
    ActiveWorkbook.SaveCopyAs ActiveWorkbook.Path & "\" & nom
    rep = MsgBox("Votre commande est sauvegardée sous le nom :" & vbCrLf & vbCrLf & " " & nom, vbYes + vbInformation, "Copie sauvegarde commande")
 
    Cells(1, 6) = Date & " " & Time
 
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
        IgnorePrintAreas:=False
 
    Range("D1").Select
    Selection.ClearContents
 
    Range("A5:H1000").Select
    Selection.ClearContents
 
    Range("J4") = Application.UserName
 
    Range("A5").Select
 
    ActiveWorkbook.Save
 
    MsgBox ("Commande cloturée, ouverture d'une commande vierge...")
 
    Range("A5").Select
 
    Else
 
 
 
End If
 
 
End Sub
info-bel est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/08/2011, 14h41   #2
Membre habitué
 
Homme Ludo
Inscription : février 2010
Messages : 104
Détails du profil
Informations personnelles :
Nom : Homme Ludo
Localisation : France

Informations forums :
Inscription : février 2010
Messages : 104
Points : 135
Points : 135
Bonjour,

J'ai juste rajouté les fins de conditions et mis légèrement en forme. Est-ce que cela vous convient?

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
Sub Macro9()
'
' Macro9 Macro
' Si la cellule est égale à "SPONTANEE"
If Cells(1, 4).Value = "SPONTANEE" Then
 
 
    If MsgBox("Opération irréversible. Souhaitez-vous continuez ?", vbQuestion + vbYesNo, "QUESTION ...") = vbYes Then
 
        nom = Format(Date, "yyyy-mm-dd") & "   " & Format(Time, "hh-mm") & "   " & " SPONTANEE " & ActiveWorkbook.Name
        ActiveWorkbook.SaveCopyAs ActiveWorkbook.Path & "\" & nom
        rep = MsgBox("Votre commande spontannée est sauvegardée sous le nom :" & vbCrLf & vbCrLf & " " & nom, vbYes + vbInformation, "Copie sauvegarde commande")
 
        ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
        IgnorePrintAreas:=False
        Range("A5:H1000").Select
        Selection.ClearContents
 
        Range("J3").Select
        ActiveCell.FormulaR1C1 = "CLOTUREE"
 
 
 
        Range("A5").Select
 
        ThisWorkbook.Close SaveChanges:=False
        MsgBox (" Commande spontannée sauvegardée. Fermeture d'excel.")
        Application.Quit
 
    End If
'Si la cellule est différente de "SPONTANEE"
Else
 
    If MsgBox("Attention ! Opération irréversible." & vbCrLf & vbCrLf & "Souhaitez-vous clôturer la commande ?", vbQuestion + vbYesNo, "QUESTION ...") = vbYes Then
 
        nom = Format(Date, "yyyy-mm-dd") & "   " & Format(Time, "hh-mm") & "   " & ActiveWorkbook.Name
        ActiveWorkbook.SaveCopyAs ActiveWorkbook.Path & "\" & nom
        rep = MsgBox("Votre commande est sauvegardée sous le nom :" & vbCrLf & vbCrLf & " " & nom, vbYes + vbInformation, "Copie sauvegarde commande")
 
        Cells(1, 6) = Date & " " & Time
 
        ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
            IgnorePrintAreas:=False
 
        Range("D1").Select
        Selection.ClearContents
 
        Range("A5:H1000").Select
        Selection.ClearContents
 
        Range("J4") = Application.UserName
 
        Range("A5").Select
 
        ActiveWorkbook.Save
 
        MsgBox ("Commande cloturée, ouverture d'une commande vierge...")
 
        Range("A5").Select
 
     End If
 
End If
Je pense que vous avez confondus les End If avec les Else.
__________________
Cordialement
LouiMz est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/08/2011, 14h48   #3
Invité de passage
 
Femme
Inscription : août 2011
Messages : 10
Détails du profil
Informations personnelles :
Sexe : Femme

Informations forums :
Inscription : août 2011
Messages : 10
Points : 0
Points : 0
Grand merci, c'est super.

Malheureusement, mon niveau en VBA est très bas, merci pour le partage de vos compétences.

info-bel est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 03h08.


 
 
 
 
Partenaires

Hébergement Web