Ceci est une page optimisée pour les mobiles. Cliquez sur ce texte pour afficher la vraie page.

Simplifier un code IF

chaelie2015

XLDnaute Accro
Bonjour Forum
je souhaite simplifier ce code si c'est possible
Code:
Sub MES_PREVUE()

If TextBox10 <> "" And TextBox11 <> "" And [COLOR="#FF0000"]ComboBox8.Value = "Mois"[/COLOR] Then _
TextBox14.Value = DateAdd("m", TextBox11, TextBox10) Else TextBox14 = ""

If TextBox10 <> "" And TextBox11 <> "" And [COLOR="#FFFF00"]ComboBox8.Value = "Jour(s)"[/COLOR] Then _
TextBox14.Value = DateAdd("d", TextBox11, TextBox10) Else TextBox14 = ""

If TextBox10 <> "" And TextBox11 <> "" And [COLOR="#00FF00"]ComboBox8.Value = ""[/COLOR] Then _
TextBox14.Value = ""

End Sub
merci par avance
 

Lone-wolf

XLDnaute Barbatruc
Re : Simplifier un code IF

Bonjour chaelie,

peut-être comme ceci

Code:
Sub MES_PREVUE()
If ComboBox8.Value = "Mois" then
TextBox14.Value = DateAdd("m", TextBox11, TextBox10)
ElseIf ComboBox8.Value = "Jour(s)" then
TextBox14.Value = DateAdd("d", TextBox11, TextBox10)
Else
TextBox14.Value = ""
End If
End Sub

Mais avec un fichier joint, ce serait plus simple, non ?. De plus je ne comprends pas pourquoi Tb10 + Tb11 pour extraire une date. Est-ce que tu utilise MonthView ?



Amicalement Lone-wolf
 
Dernière édition:

Lone-wolf

XLDnaute Barbatruc
Re : Simplifier un code IF

Une autre façon de faire


Code:
Private Sub UserForm_Initialize()
With Me.ComboBox1
.AddItem "Mois"
.AddItem "Jour(s)"
.AddItem "Rien"
End With
End Sub

Private Sub ComboBox1_Change()
If ComboBox1.Value = "Mois" Then
TextBox2.Value = TextBox1
TextBox2 = Format(TextBox1, "mmmm")
ElseIf ComboBox1.Value = "Jour(s)" Then
TextBox2.Value = TextBox1
TextBox2 = Format(TextBox1, "dddd")
Else
TextBox2.Value = ""
End If
End Sub


A+ Lone-wolf
 
Les cookies sont requis pour utiliser ce site. Vous devez les accepter pour continuer à utiliser le site. En savoir plus…