VBA/Feuilles

O

Ouin-Ouin

Guest
Bonsoir tout le Forum,

Je suis arrivé au bout de mes satanés IF en VBA mais il me reste une question?

Comment faire pour lui faire comprendre que mon deuxième IF ( le dernier celui que vous mets ci-dessous) doit aller en AnnexeV s'il répond aux conditions? En effet maintenant il et en AnnexeV et en AnnexeII ceci probablement parce que le la valeur du TextBox9 est M dans les deux cas ce qui peut arriver mais si la valeur du TextBox9="M" et en plus la valeur du TextBox14=1.5 il doit aller en AnnexeV sinon en AnnexeII


Comme cela il va se mettre et dans la feuille AnnexeII et dans la feuille AnnexeV alors ces conditions doivent aller seulement en AnnexeV

If TextBox14 = 1.5 And TextBox9 = "M" Then
.Cells(Ligne, 10) = TextBox13
Else
If TextBox14 = 1.5 Then .Cells(Ligne, 12) = TextBox13


End If

End With


End Sub

Merci de votre aide et bonne soirée
Ouin-Ouin
 
O

Ouin-Ouin

Guest
Bonjour tout le Forum,
Je crois que j'ai pas été très claire dans ma demande alors je la re-formule différemment...
mes deux IF fonctionnent mais doivent être séparé clairement chaqun à sa place
Le premier pour la feuille AnnexeII et seulement pour cette feuille
Le deuxième pour la feuille AnnexeV et seulement pour cette feuille
Merci et excellente journée Ouin-Ouin


With TheBaseBook.Sheets("AnnexeII") 'vu qu'on a deux classeurs à ce moment là...
Ligne = .Range("B65536").End(xlUp).Row + 1

.Range("B" & CStr(Ligne)) = TextBox16
.Range("C" & CStr(Ligne)) = TextBox15
.Range("D" & CStr(Ligne)) = TextBox2
.Range("E" & CStr(Ligne)) = TextBox9
.Range("F" & CStr(Ligne)) = ComboBox1
.Range("G" & CStr(Ligne)) = TextBox3
.Range("H" & CStr(Ligne)) = TextBox8
.Range("I" & CStr(Ligne)) = TextBox5

.Range("O" & CStr(Ligne)) = Label2
.Range("N" & CStr(Ligne)) = Label1

.Range("J" & CStr(Ligne)).NumberFormat = "#,###,###0.000"
.Range("L" & CStr(Ligne)).NumberFormat = "#,###,###0.000"
.Range("N" & CStr(Ligne)).NumberFormat = "#,###,###0.000"
.Range("O" & CStr(Ligne)).NumberFormat = "#,###,###0.000"

.Cells(Ligne, 1) = Ligne - 2


'' Si TextBox14 = 5 alors la valeur du TextBox13 se met en colonne "J" si la valeur
'' du TextBox14 est de "5" ou "10" alors la valuer du TextBox13 se met en "L"
'Merci Didier_mdf forum Excel pour toute son aide


If TextBox14 = 2.5 Then
.Cells(Ligne, 12) = TextBox13
Else
If TextBox14 = "5" Or "10" Then .Cells(Ligne, 10) = TextBox13


End If

End With

With TheBaseBook.Sheets("AnnexeV") 'vu qu'on a deux classeurs à ce moment là...
Ligne = .Range("B65536").End(xlUp).Row + 1

.Range("B" & CStr(Ligne)) = TextBox16
.Range("C" & CStr(Ligne)) = TextBox15
.Range("D" & CStr(Ligne)) = TextBox2
.Range("E" & CStr(Ligne)) = TextBox9
.Range("F" & CStr(Ligne)) = ComboBox1
.Range("G" & CStr(Ligne)) = TextBox3
.Range("H" & CStr(Ligne)) = TextBox8
.Range("I" & CStr(Ligne)) = TextBox5

.Range("O" & CStr(Ligne)) = Label2
.Range("N" & CStr(Ligne)) = Label1

.Range("J" & CStr(Ligne)).NumberFormat = "#,###,###0.000"
.Range("L" & CStr(Ligne)).NumberFormat = "#,###,###0.000"
.Range("N" & CStr(Ligne)).NumberFormat = "#,###,###0.000"
.Range("O" & CStr(Ligne)).NumberFormat = "#,###,###0.000"

.Cells(Ligne, 1) = Ligne - 2

If TextBox14 = 1.5 And TextBox9 = "M" Then
.Cells(Ligne, 10) = TextBox13
Else
If TextBox14 = 1.5 Then .Cells(Ligne, 12) = TextBox13


End If

End With


End Sub
 
@

@+Thierry

Guest
Salut Ouin Ouin, le Forum

Je n'ai pas cherché à adapter à ton fichier car beaucoup trop long à faire pour le temps que j'ai de dispo...

Mais voici comment faire ton Test sur des IF :

Private Sub CommandButton1_Click()
If TextBox1 = 1.5 And TextBox2 = "M" Then
MsgBox "La TextBox1 et la TextBox2 remplissent les deux Conditions 1.5 et M"
ElseIf TextBox1 = 1.5 Then
MsgBox "Seule La TextBox1 remplit la Condition 1.5"
Else
MsgBox "Aucune des TextBoxs ne remplit les conditions "
End If
End Sub

Car ton :
If Condition And Contion Then
Action
Else
If Condition Then Action
End If
Est assez tordu niveau syntax ....

Bon Courage
@+Thierry
 
O

Ouin-Ouin

Guest
Voilà toute la nouvelle procédure revue et corrigée
( surtout la formulation des IF ) Un tout grand merci à LaurentTBT pour sa précieuse collaboration matinale



With TheBaseBook.Sheets("AnnexeII") 'vu qu'on a deux classeurs à ce moment là...
Ligne = .Range("B65536").End(xlUp).Row + 1

.Cells(Ligne, 1) = Ligne - 2

If TextBox14 = 2.5 Then

.Cells(Ligne, 2) = TextBox16
.Cells(Ligne, 3) = TextBox15
.Cells(Ligne, 4) = TextBox2
.Cells(Ligne, 5) = TextBox9
.Cells(Ligne, 6) = ComboBox1
.Cells(Ligne, 7) = TextBox3
.Cells(Ligne, 8) = TextBox8
.Cells(Ligne, 9) = TextBox5
.Cells(Ligne, 12) = TextBox13

.Range("O" & CStr(Ligne)) = Label2
.Range("N" & CStr(Ligne)) = Label1

.Range("J" & CStr(Ligne)).NumberFormat = "#,###,###0.000"
.Range("L" & CStr(Ligne)).NumberFormat = "#,###,###0.000"
.Range("N" & CStr(Ligne)).NumberFormat = "#,###,###0.000"
.Range("O" & CStr(Ligne)).NumberFormat = "#,###,###0.000"


Else
If TextBox14 = "5" Or TextBox14 = "10" Then

.Cells(Ligne, 2) = TextBox16
.Cells(Ligne, 3) = TextBox15
.Cells(Ligne, 4) = TextBox2
.Cells(Ligne, 5) = TextBox9
.Cells(Ligne, 6) = ComboBox1
.Cells(Ligne, 7) = TextBox3
.Cells(Ligne, 8) = TextBox8
.Cells(Ligne, 9) = TextBox5
.Cells(Ligne, 10) = TextBox13

.Range("O" & CStr(Ligne)) = Label2
.Range("N" & CStr(Ligne)) = Label1

.Range("J" & CStr(Ligne)).NumberFormat = "#,###,###0.000"
.Range("L" & CStr(Ligne)).NumberFormat = "#,###,###0.000"
.Range("N" & CStr(Ligne)).NumberFormat = "#,###,###0.000"
.Range("O" & CStr(Ligne)).NumberFormat = "#,###,###0.000"


End If
End If

End With



'Merci Didier_mdf forum Excel pour toute son aide



With TheBaseBook.Sheets("AnnexeV") 'vu qu'on a deux classeurs à ce moment là...
Ligne = .Range("B65536").End(xlUp).Row + 1

.Cells(Ligne, 1) = Ligne - 2

If TextBox14 = 1.5 Then
If TextBox9 = "M" Then

.Cells(Ligne, 2) = TextBox16
.Cells(Ligne, 3) = TextBox15
.Cells(Ligne, 4) = TextBox2
.Cells(Ligne, 5) = TextBox9
.Cells(Ligne, 6) = ComboBox1
.Cells(Ligne, 7) = TextBox3
.Cells(Ligne, 8) = TextBox8
.Cells(Ligne, 9) = TextBox5
.Cells(Ligne, 10) = TextBox13

.Range("O" & CStr(Ligne)) = Label2
.Range("N" & CStr(Ligne)) = Label1

.Range("J" & CStr(Ligne)).NumberFormat = "#,###,###0.000"
.Range("L" & CStr(Ligne)).NumberFormat = "#,###,###0.000"
.Range("N" & CStr(Ligne)).NumberFormat = "#,###,###0.000"
.Range("O" & CStr(Ligne)).NumberFormat = "#,###,###0.000"


Else

.Cells(Ligne, 2) = TextBox16
.Cells(Ligne, 3) = TextBox15
.Cells(Ligne, 4) = TextBox2
.Cells(Ligne, 5) = TextBox9
.Cells(Ligne, 6) = ComboBox1
.Cells(Ligne, 7) = TextBox3
.Cells(Ligne, 8) = TextBox8
.Cells(Ligne, 9) = TextBox5
.Cells(Ligne, 12) = TextBox13

.Range("O" & CStr(Ligne)) = Label2
.Range("N" & CStr(Ligne)) = Label1

.Range("J" & CStr(Ligne)).NumberFormat = "#,###,###0.000"
.Range("L" & CStr(Ligne)).NumberFormat = "#,###,###0.000"
.Range("N" & CStr(Ligne)).NumberFormat = "#,###,###0.000"
.Range("O" & CStr(Ligne)).NumberFormat = "#,###,###0.000"


End If
End If

End With


End Sub

'Merci LaurentTBT forum Excel pour toute son aide

@plus pour de nouvelles aventures
Bon app Ouin-Ouin
 

Discussions similaires

Statistiques des forums

Discussions
312 329
Messages
2 087 334
Membres
103 519
dernier inscrit
Thomas_grc11