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
39"), 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
39"), 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
39"), 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
39"), 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
39"), 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
39"), 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