Sub suiviRdVClients()
Application.EnableEvents = False
Application.ScreenUpdating = False
Dim wb As Workbook
Dim ws As Worksheet
'PREPARATION OUVERTUR FICHIER NOMME
Set wb = Workbooks.Open("C:\Users\lionel\Desktop\01 isitelFacturation Nouveau\isitelFacturation Nouveau.xlsm") 'Préparation ouverture…
Set ws = wb.Worksheets(1)
Sheets("suiviRdV").Select
ActiveSheet.Unprotect Password:=""
[B1].FormulaR1C1 = "=SUM(R[3]C[27]:R[1500]C[27])"
[G1].FormulaR1C1 = "=CONCATENATE(""Vendeur(s)"","" "",SUM(R[3]C[73]:R[1500]C[73]),"" / "", SUM(R[3]C[74]:R[1500]C[74]))"
[Z1].FormulaR1C1 = "=CONCATENATE(""Nbr"","" "",SUM(R[3]C:R[1500]C))"
[AB1].FormulaR1C1 = "=CONCATENATE(""lign"","" "",SUM(R[3]C[54]:R[1500]C[54]))"
[N2].FormulaR1C1 = "=SUM(R[2]C:R[1500]C)"
[P2].FormulaR1C1 = "=SUM(R[2]C:R[1500]C)"
[R2].FormulaR1C1 = "=SUM(R[2]C:R[1500]C)"
[T2].FormulaR1C1 = "=SUM(R[2]C:R[1500]C)"
[V2].FormulaR1C1 = "=SUM(R[2]C:R[1500]C)"
[X2].FormulaR1C1 = "=SUM(R[2]C:R[1500]C)"
[Y2].FormulaR1C1 = "=SUM(R[2]C[57]:R[1500]C[57])-SUM(R[2]C[55]:R[1500]C[55])-((SUM(R[2]C[57]:R[1500]C[57])-SUM(R[2]C[56]:R[1500]C[56])))"
[AB2].FormulaR1C1 = "=CONCATENATE(SUM(R[2]C[52]:R[1500]C[52]),"" "",RC[54]-RC[53],"" "")"
[AC2].FormulaR1C1 = "=SUM(R[2]C:R[1500]C)"
[CB2].FormulaR1C1 = "=SUM(R[2]C:R[15000]C)"
[CC2].FormulaR1C1 = "=SUM(R[2]C:R[15000]C)"
[CD2].FormulaR1C1 = "=SUM(R[2]C:R[15000]C)"
'C'EST LE 1er TRAITEMENT DU MOIS ?
If MsgBox(" C'est le 1er traitement du mois ?" & Chr(10) & Chr(10) & "OUI ou NON", vbQuestion + vbYesNo) <> vbYes Then
[ci1] = "En Cours"
'Exit Sub
Else
[ci1] = ""
End If
'SI 1er TRAITEMENT
If [ci1] = "" Then
Rows("4:3000").ClearContents
[B1].FormulaR1C1 = "=SUM(R[3]C[27]:R[1500]C[27])"
[G1].FormulaR1C1 = "=CONCATENATE(""Vendeur(s)"","" "",SUM(R[3]C[73]:R[1500]C[73]),"" / "", SUM(R[3]C[74]:R[1500]C[74]))"
[Z1].FormulaR1C1 = "=CONCATENATE(""Nbr"","" "",SUM(R[3]C:R[1500]C))"
[AB1].FormulaR1C1 = "=CONCATENATE(""lign"","" "",SUM(R[3]C[54]:R[1500]C[54]))"
[N2].FormulaR1C1 = "=SUM(R[2]C:R[1500]C)"
[P2].FormulaR1C1 = "=SUM(R[2]C:R[1500]C)"
[R2].FormulaR1C1 = "=SUM(R[2]C:R[1500]C)"
[T2].FormulaR1C1 = "=SUM(R[2]C:R[1500]C)"
[V2].FormulaR1C1 = "=SUM(R[2]C:R[1500]C)"
[X2].FormulaR1C1 = "=SUM(R[2]C:R[1500]C)"
[Y2].FormulaR1C1 = "=SUM(R[2]C[57]:R[1500]C[57])-SUM(R[2]C[55]:R[1500]C[55])-((SUM(R[2]C[57]:R[1500]C[57])-SUM(R[2]C[56]:R[1500]C[56])))"
[AB2].FormulaR1C1 = "=CONCATENATE(SUM(R[2]C[52]:R[1500]C[52]),"" "",RC[54]-RC[53],"" "")"
[AC2].FormulaR1C1 = "=SUM(R[2]C:R[1500]C)"
[CB2].FormulaR1C1 = "=SUM(R[2]C:R[15000]C)"
[CC2].FormulaR1C1 = "=SUM(R[2]C:R[15000]C)"
[CD2].FormulaR1C1 = "=SUM(R[2]C:R[15000]C)"
End If
[CI3].FormulaR1C1 = "=IF(RC[-85]="""","""",IF(RC[-1]=R[1]C[-1],"""",IF(LOOKUP(RC[-1],ClientsF)<>"""",LOOKUP(RC[-1],ClientsF),IF(RC[-85]<>"""",CONCATENATE(LOOKUP(RC[-1],Clients),"" "",LOOKUP(RC[-1],Clients1)),0))))"
[CJ3].FormulaR1C1 = "=IF(RC[-86]="""",0,IF(RC[-2]<>R[-1]C[-2],1,R[-1]C+1))"
'COPIE LIGNE MODELE
Rows("3:3").Select
Selection.RowHeight = 45
[b3:e3].FormulaR1C1 = ""
Selection.Copy
ActiveSheet.Cells(Rows.Count, "a").End(xlUp)(2).EntireRow.Select
'ActiveCell.Rows.EntireRow.Select
ActiveSheet.Paste
[b3:e3].FormulaR1C1 = "1"
Rows("3:3").RowHeight = 0
'SI 1er TRAITEMENT
If [ci1] = "" Then
[M4:X500].ClearContents
[Z4:Z500].ClearContents
Else
With Cells(Rows.Count, "A").End(xlUp)
Rows(.Row).Copy Cells(.Row, "A").Offset(1).Resize(1500)
Cells(.Row, "A").Offset(2).Select
End With
[A4:A2000].Replace What:="1", Replacement:="", LookAt:=xlWhole, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
[a1].Select
End If
'SELECTION FICHIER RDdVs
On Error Resume Next
Windows("isitelImmobRdV ImenNF.xlsm").Activate
Windows("isitelImmobRdV SondaNF.xlsm").Activate
Windows("isitelImmobRdV StephanieNF.xlsm").Activate
Sheets("RendezVous").Select
ActiveSheet.Unprotect Password:="Krameri"
'TRAITE PREPARATION DES RdVs A FACTURER
Range("B4").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-1]=1,""OUI"",1)"
Selection.Copy
Range("B5:B500").Select
ActiveSheet.Paste
Range("B4:B500").Select
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B4:B500").Select
Selection.Replace What:=1, Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
On Error Resume Next
Columns(3).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
TrieMandatsOUI
'REVIENT SUR FACTURATION
Windows("isitelFacturation Nouveau.xlsm").Activate
Sheets("suiviRdV").Select
'SiActif
If [ci1] = "" Then
ActiveSheet.Cells(Rows.Count, "a").End(xlUp)(3).Select
Else
ActiveSheet.Cells(Rows.Count, "a").End(xlUp)(2).Select
End If
ActiveCell.Offset(0, 0).Resize(499, 1) = Workbooks("isitelImmobRdV StephanieNF").Sheets("RendezVous").Range("L4:L502").Value
If [ci1] = "" Then
'SI 1er TRAITEMENT
ActiveSheet.Cells(Rows.Count, "b").End(xlUp)(4).Select
Else
'SI APRES er TRAITEMENT
ActiveSheet.Cells(Rows.Count, "b").End(xlUp)(2).Select
End If
ActiveCell.Offset(0, 0).Resize(499, 1) = Workbooks("isitelImmobRdV StephanieNF").Sheets("RendezVous").Range("Q4:Q502").Value
If [ci1] = "" Then
ActiveSheet.Cells(Rows.Count, "c").End(xlUp)(3).Select
Else
ActiveSheet.Cells(Rows.Count, "c").End(xlUp)(2).Select
End If
ActiveCell.Offset(0, 0).Resize(499, 1) = Workbooks("isitelImmobRdV StephanieNF").Sheets("RendezVous").Range("S4:S502").Value
If [ci1] = "" Then
ActiveSheet.Cells(Rows.Count, "d").End(xlUp)(3).Select
Else
ActiveSheet.Cells(Rows.Count, "d").End(xlUp)(2).Select
End If
ActiveCell.Offset(0, 0).Resize(499, 1) = Workbooks("isitelImmobRdV StephanieNF").Sheets("RendezVous").Range("V4:V502").Value
If [ci1] = "" Then
ActiveSheet.Cells(Rows.Count, "e").End(xlUp)(3).Select
Else
ActiveSheet.Cells(Rows.Count, "e").End(xlUp)(2).Select
End If
ActiveCell.Offset(0, 0).Resize(499, 1) = Workbooks("isitelImmobRdV StephanieNF").Sheets("RendezVous").Range("F4:F502").Value
If [ci1] = "" Then
ActiveSheet.Cells(Rows.Count, "f").End(xlUp)(4).Select
Else
ActiveSheet.Cells(Rows.Count, "f").End(xlUp)(2).Select
End If
ActiveCell.Offset(0, 0).Resize(499, 1) = Workbooks("isitelImmobRdV StephanieNF").Sheets("RendezVous").Range("C4:C502").Value
If [ci1] = "" Then
ActiveSheet.Cells(Rows.Count, "g").End(xlUp)(4).Select
Else
ActiveSheet.Cells(Rows.Count, "g").End(xlUp)(2).Select
End If
ActiveCell.Offset(0, 0).Resize(499, 1) = Workbooks("isitelImmobRdV StephanieNF").Sheets("RendezVous").Range("AD4:AD502").Value
If [ci1] = "" Then
ActiveSheet.Cells(Rows.Count, "h").End(xlUp)(4).Select
Else
ActiveSheet.Cells(Rows.Count, "h").End(xlUp)(2).Select
End If
ActiveCell.Offset(0, 0).Resize(499, 1) = Workbooks("isitelImmobRdV StephanieNF").Sheets("RendezVous").Range("AE4:AE502").Value
If [ci1] = "" Then
ActiveSheet.Cells(Rows.Count, "i").End(xlUp)(4).Select
Else
ActiveSheet.Cells(Rows.Count, "i").End(xlUp)(2).Select
End If
ActiveCell.Offset(0, 0).Resize(499, 1) = Workbooks("isitelImmobRdV StephanieNF").Sheets("RendezVous").Range("AF4:AF502").Value
If [ci1] = "" Then
ActiveSheet.Cells(Rows.Count, "j").End(xlUp)(4).Select
Else
ActiveSheet.Cells(Rows.Count, "j").End(xlUp)(2).Select
End If
ActiveCell.Offset(0, 0).Resize(499, 1) = Workbooks("isitelImmobRdV StephanieNF").Sheets("RendezVous").Range("AG4:AG502").Value
'ICI ICI ICI Ne prend pas les chiffres
If [ci1] = "" Then
ActiveSheet.Cells(Rows.Count, "m").End(xlUp)(4).Select
Else
ActiveSheet.Cells(Rows.Count, "m").End(xlUp)(2).Select
End If
ActiveCell.Offset(0, 0).Resize(499, 1) = Workbooks("isitelImmobRdV StephanieNF").Sheets("RendezVous").Range("AI4:AT502").Value
If [ci1] = "" Then
[z4:z3000].ClearContents
ActiveSheet.Cells(Rows.Count, "Z").End(xlUp)(3).Select
Else
ActiveSheet.Cells(Rows.Count, "AA").End(xlUp)(2).Select
ActiveCell.Offset(0, -1).Select
End If
ActiveCell.Offset(0, 0).Resize(499, 2) = Workbooks("isitelImmobRdV StephanieNF").Sheets("RendezVous").Range("A4:B502").Value
Rows("503:3000").Delete
Columns("Z:Z").Select
Selection.Replace What:="0", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
[Y2].FormulaR1C1 = "=SUM(R[2]C[55]:R[500]C[55])"
[AB1].FormulaR1C1 = "=CONCATENATE(""lign"","" "",SUM(R[3]C[52]:R[1006]C[52]))"
[AB2].FormulaR1C1 = "=CONCATENATE(SUM(R[2]C[52]:R[500]C[52]),"" "",SUM(R[2]C[53]:R[500]C[53]),"" "",SUM(R[2]C[-2]:R[500]C[-2]))"
Rows("4:500").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Rows("4:500").Select
ActiveWorkbook.Worksheets("suiviRdV").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("suiviRdV").Sort.SortFields.Add2 Key:=Range( _
"Z4:Z500"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("suiviRdV").Sort
.SetRange Range("A4:CJ500")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
[a1].Select
Columns(26).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
Range("B3").Select
Sheets("suiviRdV").Select '???
On Error Resume Next
Windows("isitelImmobRdV ImenNF.xlsm").Activate
Windows("isitelImmobRdV SondaNF.xlsm").Activate
Windows("isitelImmobRdV StephanieNF.xlsm").Activate
ActiveWindow.SmallScroll Down:=-51
Range("A2").Select
Sheets("RendezVous").Select
'RdVFin
Application.EnableEvents = True
Application.ScreenUpdating = True
ActiveWorkbook.Save
ActiveWindow.Close
End Sub