Bonjour à tous,
Un essai ...
Dès le remplacement du . par la , ... je fais diviser la donnée par 10.
Puis, une fois le format de cellule appliqué, il faut multiplier par 10 pour rétablir la valeur.
Ça semble fonctionner correctement.
Public Sub sumdel2()
Set ws = Worksheets("CSV")
Set ws2 = Worksheets("VNEI (EI)")
'Classer les données (A-Z) dans la colonne B
lrws2 = ws2.Cells(Rows.Count, 2).End(xlUp).Row
With ws2
Range(Cells(1, 1), Cells(lrws2, 10)).Sort _
Key1:=Range("B1"), order1:=xlAscending, _
Header:=xlYes, Orientation:=xlTopToBottom
End With
With ws2
lrws2 = .Cells(Rows.Count, 2).End(xlUp).Row
Dim cL As Range
For Each cL In .Range(Cells(2, 4), Cells(lrws2, 4))
cL = Replace(cL, ".", ",") ' remplacer le . par la ,
cL = cL / 10 ' diviser la donnée par 10
Next cL
.Range(Cells(2, 4), Cells(lrws2, 4)).NumberFormat = "#,##0.00" ' appliquer le format
For Each cL In .Range(Cells(2, 4), Cells(lrws2, 4))
cL = cL * 10 ' multiplier par 10 pour rétablir la donnée
Next cL
'Aditionner les surfaces par habitats
For lRow = lrws2 To 2 Step -1
If .Cells(lRow, 2) = .Cells(lRow - 1, 2) Then
.Cells(lRow - 1, 4) = CDbl(.Cells(lRow, 4)) + CDbl(.Cells(lRow - 1, 4))
.Rows(lRow).Delete shift:=xlUp
End If
Next
End With
End Sub
ric