If ... end if... if... if qqun pouvait m aider la-dessus??? :op

T

Thibaut

Guest
Re-re-re-bonjour... va vraiment falloir que je prenne un abonnement :eek:p
J ai donc effectué une macro dans lequel apparait un userform avec deux boutons... voici le code de chacun:


Private Sub Chauffage_Click()
UserForm2.Hide

End Sub

Private Sub Climatisation_Click()
UserForm2.Hide

End Sub


Et voici le code principal de la macro:


UserForm2.Show

If rep = Chauffage Then

(là je mets toutes les actions à réaliser)

End If

If rep = Climatisation Then

(les autres opérations à réaliser)

End If

Et bien, quelque soit le choix que je fais, il se passe exactement la même chose... alors que justement ça ne devrait pas...

Autre chose, suivant que l on fasse l un ou l auture procédure, le fichier doit se sauvegarder sous un autre nom... voici les lignes de codes (à insérer entre les "If... End if"

Dim DocName As String
DocName = "Calcul des DJ de chauffage" & " " & UserForm1.Ville & " " & UserForm1.Année
ThisWorkbook.SaveAs Filename:=DocName
MsgBox " 4/ Le fichier est sauvegardé dans le répertoire courant de la feuille contenant cette macro sous le nom 'Calcul des DJ de chauffage + le nom de la ville + l année'"
End If


et l autre:

Dim DocName As String
DocName = "Calcul des DJ de climatisation" & " " & UserForm1.Ville & " " & UserForm1.Année
ThisWorkbook.SaveAs Filename:=DocName
MsgBox " 4/ Le fichier est sauvegardé dans le répertoire courant de la feuille contenant cette macro sous le nom 'Calcul des DJ de climatisation + le nom de la ville + l année'"
End If

J ai déjà un problème à cause des deux"string"... que dois je faire???

Un tout grand merci à vous

Thibaut
 
T

Thibaut

Guest
Bon, pour plus de clarté et de commpréhension, je vais copier ici ma macro... Mon problème arrive à partir de Userfom2

Private Sub Workbook_Open()

Range("B1").Select
Selection.ClearContents
Range("C2").Select
Selection.ClearContents
Range("B3").Select
Selection.ClearContents
Range("F6:AC370").Select
Selection.ClearContents
Range("B1").Select
monchemin = ThisWorkbook.Path
ChDir (monchemin)
MsgBox " Attention, cette macro s'execute dès l'ouverture du fichier!"
MsgBox " 1/ Sélectionner le fichier où il faut aller rechercher les températures relevées!"
rep = Application.Dialogs(xlDialogOpen).Show
If rep = False Then
End
End If
Set monfichier = ActiveWorkbook

Range("E2:AB366").Select
Selection.Replace What:=",", Replacement:=".", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
Selection.NumberFormat = "0.00"
With Selection
.HorizontalAlignment = xlRight
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = False
End With
Range("E2:AB366").Select
Selection.Copy
ActiveWindow.WindowState = xlMinimized
Range("F6").Select
Selection.PasteSpecial Paste:=xlAll, Operation:=xlAdd, SkipBlanks:=False _
, Transpose:=False

Set monfichier = ActiveWorkbook


MsgBox " 2/ Veuillez remplir les champs suivants!"

Range("C2").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=Value_Change"

Range("B1").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=Ville_Change"

Range("B3").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=Année_Change"

UserForm1.Show


UserForm2.Show

If rep = Chauffage Then

Range("AH6").Select
ActiveCell.Formula = "=IF(0<$C$2-AG6;$C$2-AG6;0)"
Range("AH6").Select
Selection.AutoFill Destination:=Range("AH6:AH370"), Type:=xlFillDefault
Range("AM6").Select
ActiveCell.Formula = "=IF(0<$C$2-AL6; $C$2-AL6;0)"
Range("AM6").Select
Selection.AutoFill Destination:=Range("AM6:AM370"), Type:=xlFillDefault
Range("AR6").Select
ActiveCell.Formula = "=IF(0<C2-AQ6;C2-AQ6;0)"
Range("AR6").Select
Selection.AutoFill Destination:=Range("AR6:AR370"), Type:=xlFillDefault

Sheets("jan-apr.").Select
Range("D9").Select
ActiveCell.Formula = "=IF($J$3-((B9+C9)/2)<0;0;$J$3-((B9+C9)/2))"
Range("D9").Select
Selection.AutoFill Destination:=Range("D9:D39"), Type:=xlFillDefault
Range("G9").Select
ActiveCell.Formula = "=IF($J$3-((E9+F9)/2)<0;0;$J$3-((E9+F9)/2))"
Range("G9").Select
Selection.AutoFill Destination:=Range("G9:G36"), Type:=xlFillDefault
Range("J9").Select
ActiveCell.Formula = "=IF($J$3-((H9+I9)/2)<0;0;$J$3-((H9+I9)/2))"
Range("J9").Select
Selection.AutoFill Destination:=Range("J9:J39"), Type:=xlFillDefault
Range("M9").Select
ActiveCell.Formula = "=IF($J$3-((K9+L9)/2)<0;0;$J$3-((K9+L9)/2))"
Range("M9").Select
Selection.AutoFill Destination:=Range("M9:M38"), Type:=xlFillDefault

Sheets("mei-aug.").Select
Range("D9").Select
ActiveCell.Formula = "=IF($J$3-((B9+C9)/2)<0;0;$J$3-((B9+C9)/2))"
Range("D9").Select
Selection.AutoFill Destination:=Range("D9:D39"), Type:=xlFillDefault
Range("G9").Select
ActiveCell.Formula = "=IF($J$3-((E9+F9)/2)<0;0;$J$3-((E9+F9)/2))"
Range("G9").Select
Selection.AutoFill Destination:=Range("G9:G36"), Type:=xlFillDefault
Range("J9").Select
ActiveCell.Formula = "=IF($J$3-((H9+I9)/2)<0;0;$J$3-((H9+I9)/2))"
Range("J9").Select
Selection.AutoFill Destination:=Range("J9:J39"), Type:=xlFillDefault
Range("M9").Select
ActiveCell.Formula = "=IF($J$3-((K9+L9)/2)<0;0;$J$3-((K9+L9)/2))"
Range("M9").Select
Selection.AutoFill Destination:=Range("M9:M38"), Type:=xlFillDefault

Sheets("sep-dec.").Select
Range("D9").Select
ActiveCell.Formula = "=IF($J$3-((B9+C9)/2)<0;0;$J$3-((B9+C9)/2))"
Range("D9").Select
Selection.AutoFill Destination:=Range("D9:D39"), Type:=xlFillDefault
Range("G9").Select
ActiveCell.Formula = "=IF($J$3-((E9+F9)/2)<0;0;$J$3-((E9+F9)/2))"
Range("G9").Select
Selection.AutoFill Destination:=Range("G9:G36"), Type:=xlFillDefault
Range("J9").Select
ActiveCell.Formula = "=IF($J$3-((H9+I9)/2)<0;0;$J$3-((H9+I9)/2))"
Range("J9").Select
Selection.AutoFill Destination:=Range("J9:J39"), Type:=xlFillDefault
Range("M9").Select
ActiveCell.Formula = "=IF($J$3-((K9+L9)/2)<0;0;$J$3-((K9+L9)/2))"
Range("M9").Select
Selection.AutoFill Destination:=Range("M9:M38"), Type:=xlFillDefault

calcul
Dim DocName As String
DocName = "Calcul des DJ de chauffage" & " " & UserForm1.Ville & " " & UserForm1.Année
ThisWorkbook.SaveAs Filename:=DocName
MsgBox " 4/ Le fichier est sauvegardé dans le répertoire courant de la feuille contenant cette macro sous le nom 'Calcul des DJ de chauffage + le nom de la ville + l année'"
End If

If rep = Climatisation Then

Range("AH6").Select
ActiveCell.Formula = "=IF(0>$C$2-AG6;$C$2-AG6;0)"
Range("AH6").Select
Selection.AutoFill Destination:=Range("AH6:AH370"), Type:=xlFillDefault
Range("AM6").Select
ActiveCell.Formula = "=IF(0>$C$2-AL6; $C$2-AL6;0)"
Range("AM6").Select
Selection.AutoFill Destination:=Range("AM6:AM370"), Type:=xlFillDefault
Range("AR6").Select
ActiveCell.Formula = "=IF(0>C2-AQ6;C2-AQ6;0)"
Range("AR6").Select
Selection.AutoFill Destination:=Range("AR6:AR370"), Type:=xlFillDefault

Sheets("jan-apr.").Select
Range("D9").Select
ActiveCell.Formula = "=IF($J$3-((B9+C9)/2)>0;0;$J$3-((B9+C9)/2))"
Range("D9").Select
Selection.AutoFill Destination:=Range("D9:D39"), Type:=xlFillDefault
Range("G9").Select
ActiveCell.Formula = "=IF($J$3-((E9+F9)/2)>0;0;$J$3-((E9+F9)/2))"
Range("G9").Select
Selection.AutoFill Destination:=Range("G9:G36"), Type:=xlFillDefault
Range("J9").Select
ActiveCell.Formula = "=IF($J$3-((H9+I9)/2)>0;0;$J$3-((H9+I9)/2))"
Range("J9").Select
Selection.AutoFill Destination:=Range("J9:J39"), Type:=xlFillDefault
Range("M9").Select
ActiveCell.Formula = "=IF($J$3-((K9+L9)/2)>0;0;$J$3-((K9+L9)/2))"
Range("M9").Select
Selection.AutoFill Destination:=Range("M9:M38"), Type:=xlFillDefault

Sheets("mei-aug.").Select
Range("D9").Select
ActiveCell.Formula = "=IF($J$3-((B9+C9)/2)>0;0;$J$3-((B9+C9)/2))"
Range("D9").Select
Selection.AutoFill Destination:=Range("D9:D39"), Type:=xlFillDefault
Range("G9").Select
ActiveCell.Formula = "=IF($J$3-((E9+F9)/2)>0;0;$J$3-((E9+F9)/2))"
Range("G9").Select
Selection.AutoFill Destination:=Range("G9:G36"), Type:=xlFillDefault
Range("J9").Select
ActiveCell.Formula = "=IF($J$3-((H9+I9)/2)>0;0;$J$3-((H9+I9)/2))"
Range("J9").Select
Selection.AutoFill Destination:=Range("J9:J39"), Type:=xlFillDefault
Range("M9").Select
ActiveCell.Formula = "=IF($J$3-((K9+L9)/2)>0;0;$J$3-((K9+L9)/2))"
Range("M9").Select
Selection.AutoFill Destination:=Range("M9:M38"), Type:=xlFillDefault

Sheets("sep-dec.").Select
Range("D9").Select
ActiveCell.Formula = "=IF($J$3-((B9+C9)/2)>0;0;$J$3-((B9+C9)/2))"
Range("D9").Select
Selection.AutoFill Destination:=Range("D9:D39"), Type:=xlFillDefault
Range("G9").Select
ActiveCell.Formula = "=IF($J$3-((E9+F9)/2)>0;0;$J$3-((E9+F9)/2))"
Range("G9").Select
Selection.AutoFill Destination:=Range("G9:G36"), Type:=xlFillDefault
Range("J9").Select
ActiveCell.Formula = "=IF($J$3-((H9+I9)/2)>0;0;$J$3-((H9+I9)/2))"
Range("J9").Select
Selection.AutoFill Destination:=Range("J9:J39"), Type:=xlFillDefault
Range("M9").Select
ActiveCell.Formula = "=IF($J$3-((K9+L9)/2)>0;0;$J$3-((K9+L9)/2))"
Range("M9").Select
Selection.AutoFill Destination:=Range("M9:M38"), Type:=xlFillDefault

calcul
DocName = "Calcul des DJ de climatisation" & " " & UserForm1.Ville & " " & UserForm1.Année
ThisWorkbook.SaveAs Filename:=DocName
MsgBox " 4/ Le fichier est sauvegardé dans le répertoire courant de la feuille contenant cette macro sous le nom 'Calcul des DJ de climatisation + le nom de la ville + l année'"
End If

End Sub
Sub calcul()
MsgBox " 3/ Veuillez patienter un instant durant les calculs..."

End Sub
 

Discussions similaires

Statistiques des forums

Discussions
311 733
Messages
2 082 010
Membres
101 866
dernier inscrit
XFPRO