Sub lancement_roles()
'BOUCLE SUR LISTE DES COMMUNES
Dim a As Integer
For a = 32 To 62
Cells(a, 2).Select
'TRAITEMENT PAR COMMUNE
Sheets("commune").Select
Cells.Select
Selection.ClearContents
col1 = ""
col2 = ""
col3 = ""
col4 = ""
col5 = ""
col6 = ""
col7 = ""
col8 = ""
col9 = ""
col10 = ""
col11 = ""
col12 = ""
col13 = ""
col14 = ""
col15 = ""
col16 = ""
col17 = ""
col18 = ""
col19 = ""
col20 = ""
col21 = ""
col22 = ""
recupcom = ""
comparecom = ""
L = 0
c = 0
la = 0
ca = 0
[COLOR="red"]Sheets("Liste des communes").Select
recupcom = Cells(a, 2)[/COLOR]
L = 2
c = 2
la = 1
ca = 1
Sheets("EXPORT").Select
comparecom = Cells(L, c - 1)
While comparecom <> ""
If comparecom = recupcom Then
col1 = Cells(L, c - 1)
col2 = Cells(L, c)
col3 = Cells(L, c + 1)
col4 = Cells(L, c + 2)
col5 = Cells(L, c + 3)
col6 = Cells(L, c + 4)
col7 = Cells(L, c + 5)
col8 = Cells(L, c + 6)
col9 = Cells(L, c + 7)
col10 = Cells(L, c + 8)
col11 = Cells(L, c + 9)
col12 = Cells(L, c + 10)
col13 = Cells(L, c + 11)
col14 = Cells(L, c + 12)
col15 = Cells(L, c + 13)
col16 = Cells(L, c + 14)
col17 = Cells(L, c + 15)
col18 = Cells(L, c + 16)
col19 = Cells(L, c + 17)
col20 = Cells(L, c + 18)
col21 = Cells(L, c + 19)
col22 = Cells(L, c + 20)
Sheets("commune").Select
Cells(la, ca) = col7
Cells(la, ca + 1) = col1
Cells(la, ca + 2) = col4
Cells(la, ca + 3) = col5
Cells(la, ca + 4) = col8
Cells(la, ca + 5) = col9
Cells(la, ca + 6) = col10
Cells(la, ca + 7) = col11
Cells(la, ca + 8) = col12
Cells(la, ca + 9) = col6
Cells(la, ca + 10) = col2
Cells(la, ca + 11) = col3
Cells(la, ca + 12) = col13
Cells(la, ca + 13) = col14
Cells(la, ca + 14) = col15
Cells(la, ca + 15) = col16
Cells(la, ca + 16) = col17
Cells(la, ca + 17) = col18
Cells(la, ca + 18) = col19
Cells(la, ca + 19) = col20
Cells(la, ca + 20) = col21
Cells(la, ca + 21) = col22
la = la + 1
End If
Sheets("EXPORT").Select
L = L + 1
comparecom = Cells(L, c - 1)
Wend
Sheets("ETAT").Select
Range("A5:Z8000").Select
Selection.ClearContents
Selection.ClearFormats
'CONSTRUCTION TABLEAU
Sheets("Commune").Select
L = 0
c = 0
la = 0
ca = 0
propriétaire = ""
section = ""
numéro = ""
classe = ""
surface = ""
degrés = ""
vannage = 0
tc1 = 0
td1 = 0#
tc2 = 0
td2 = 0#
tc3 = 0
td3 = 0#
tc4 = 0
td4 = 0#
tc5 = 0
td5 = 0#
tcHC = 0
tdHC = 0#
surtot = 0
dtot = 0
totsur = 0
tarif = 0#
affpop = 0
payer = 0#
surglobal = 0
dglobal = 0
dvan = 0
adresse = ""
cptprod = 0
amont = ""
prénom = ""
van = ""
com = ""
L = 1
c = 1
la = 5
ca = 1
cpt = 0
Sheets("Commune").Select
wpropriétaire = Cells(L, c + 10) & " " + Cells(L, c + 11)
wnuméro = Cells(L, c + 3)
wsection = Cells(L, c + 2)
cptprod = 1
propriétaire = Cells(L, c + 10) & " " + Cells(L, c + 11)
prénom = Cells(L, c + 11)
numéro = Cells(L, c + 3)
section = Cells(L, c + 2)
adresse = Cells(L, c + 18) & " " & Cells(L, c + 19) & " " & Cells(L, c + 20) & " " & Cells(L, c + 21)
While wpropriétaire <> " "
While wpropriétaire = propriétaire
While numéro = wnuméro And section = wsection
classe = Cells(L, c + 8)
surface = Cells(L, c + 6)
degrés = Cells(L, c + 17)
van = Cells(L, c + 15)
vannage = Cells(L, c + 16)
tarif = Cells(L, c + 14)
amont = Cells(L, c + 12)
If amont = True Then
If classe = 1 Then
tc1 = tc1 + surface
dc1 = dc1 + degrés
End If
If classe = 2 Then
tc2 = tc2 + surface
dc2 = dc2 + degrés
End If
If classe = 3 Then
tc3 = tc3 + surface
dc3 = dc3 + degrés
End If
If classe = 4 Then
tc4 = tc4 + surface
dc4 = dc4 + degrés
End If
If classe = 5 Then
tc5 = tc5 + surface
dc5 = dc5 + degrés
End If
If classe = "HC" Then
tcHC = tcHC + surface
dcHC = dcHC + degrés
End If
surtot = tc1 + tc2 + tc3 + tc4 + tc5 + tcHC
dtot = dc1 + dc2 + dc3 + dc4 + dc5 + dcHC
Else
If classe = 1 Then
tc1 = tc1 + surface
dc1 = 0
End If
If classe = 2 Then
tc2 = tc2 + surface
dc2 = 0
End If
If classe = 3 Then
tc3 = tc3 + surface
dc3 = 0
End If
If classe = 4 Then
tc4 = tc4 + surface
dc4 = 0
End If
If classe = 5 Then
tc5 = tc5 + surface
dc5 = 0
End If
If classe = "HC" Then
tcHC = tcHC + surface
dcHC = dcHC + degrés
End If
surtot = tc1 + tc2 + tc3 + tc4 + tc5 + tcHC
dtot = dc1 + dc2 + dc3 + dc4 + dc5 + dcHC
End If
L = L + 1
numéro = Cells(L, c + 3)
section = Cells(L, c + 2)
Wend
Sheets("ETAT").Select
If affpop = 0 Then
Cells(la, ca) = cptprod
Cells(la, ca + 1) = wpropriétaire
la = la + 1
Cells(la, ca + 1) = adresse
la = la + 1
cptprod = cptprod + 1
affpop = 1
End If
Cells(la, ca + 2) = wsection
Cells(la, ca + 3) = wnuméro
Cells(la, ca + 4) = tc1
Cells(la, ca + 5) = Round(dc1, 1)
Cells(la, ca + 6) = tc2
Cells(la, ca + 7) = Round(dc2, 1)
Cells(la, ca + 8) = tc3
Cells(la, ca + 9) = Round(dc3, 1)
Cells(la, ca + 10) = tc4
Cells(la, ca + 11) = Round(dc4, 1)
Cells(la, ca + 12) = tc5
Cells(la, ca + 13) = Round(dc5, 1)
Cells(la, ca + 14) = tcHC
Cells(la, ca + 15) = Round(dcHC, 1)
If van = True Then
Cells(la, ca + 17) = "1"
Cells(la, ca + 18) = vannage
dvan = vannage
Else
Cells(la, ca + 17) = "0"
Cells(la, ca + 18) = ""
End If
la = la + 1
tc1 = 0
dc1 = 0
tc2 = 0
dc2 = 0
tc3 = 0
dc3 = 0
tc4 = 0
dc4 = 0
tc5 = 0
dc5 = 0
tcHC = 0
dcHC = 0
van = ""
vannage = 0
Sheets("Commune").Select
wnuméro = numéro
wsection = section
propriétaire = Cells(L, c + 10) & " " + Cells(L, c + 11)
prénom = Cells(L, c + 11)
cpt = cpt + 1
surglobal = surglobal + surtot
dglobal = dglobal + dtot
dtot = 0
surtot = 0
Wend
Sheets("ETAT").Select
Selection.Font.Bold = True
Cells(la - 1, ca + 16) = surglobal
Cells(la - 1, ca + 19) = Round(dglobal + dvan, 0)
payer = (dglobal + dvan) * tarif
If payer > 8 Then
Cells(la - 1, ca + 22) = Round((dglobal + dvan) * tarif, 2)
Else
If dglobal <> 0 Then
If dglobal > 0.5 Then
Cells(la - 1, ca + 22) = 8#
Else
Cells(la - 1, ca + 22) = 0#
End If
Else
Cells(la - 1, ca + 22) = 0#
End If
End If
Selection.Font.Bold = False
Rows(la - 1).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
Selection.Borders(xlEdgeRight).LineStyle = xlNone
If cpt < 1 Then
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
End If
Cells(la - 1, 1).Select
surtot = 0
dtot = 0
payer = 0
cpt = 0
surglobal = 0
dglobal = 0
dvan = 0
vannage = 0
Sheets("Commune").Select
wpropriétaire = propriétaire
cp = ""
If Len(Cells(L, c + 20)) < 5 Then
cp = "0" & Cells(L, c + 20)
Else
cp = Cells(L, c + 20)
End If
adresse = Cells(L, c + 18) & " " & Cells(L, c + 19) & " " & cp & " " & Cells(L, c + 21)
affpop = 0
cp = ""
Wend
Sheets("ETAT").Select
Range("C5:Z800").Select
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
'With Selection.Borders(xlEdgeTop)
' .LineStyle = xlContinuous
' .Weight = xlThin
' .ColorIndex = xlAutomatic
'End With
'With Selection.Borders(xlEdgeBottom)
' .LineStyle = xlContinuous
' .Weight = xlMedium
' .ColorIndex = xlAutomatic
'End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
'With Selection.Borders(xlInsideHorizontal)
' .LineStyle = xlContinuous
' .Weight = xlThin
' .ColorIndex = xlAutomatic
'End With
Range("A5:A800").Select
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
'With Selection.Borders(xlEdgeTop)
' .LineStyle = xlContinuous
' .Weight = xlThin
' .ColorIndex = xlAutomatic
'End With
'With Selection.Borders(xlEdgeBottom)
' .LineStyle = xlContinuous
' .Weight = xlMedium
' .ColorIndex = xlAutomatic
'End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
'calcul de somme en fin de tableaux + export feuille dans un autre fichier
Dim x As Integer
x = Range("Q65536").End(xlUp).Row
Range("Q" & x + 1) = Evaluate("sum(Q2:Q" & L & ")")
Dim Y As Integer
Y = Range("T65536").End(xlUp).Row
Range("T" & Y + 1) = Evaluate("sum(T2:T" & L & ")")
Dim Z As Integer
Z = Range("Q65536").End(xlUp).Row
Range("W" & Z + 1) = Evaluate("sum(W2:W" & L & ")")
Sheets("ETAT").Select
Sheets("ETAT").Copy Before:=Workbooks("Roles.xls").Sheets(1)
ActiveSheet.Name = Sheets("ETAT").Range("B1")
Range("B1").Value = ActiveSheet.Name
Next a
End Sub