1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| Sub Tableau1()
Dim a, ada, aRow,aCol, x, y,valeur,plage,ligne,tableau(100)
' on sélectionne la zone à trier de la première feuille
a = ThisComponent.Sheets(0).getCellRangeByName("A1:G10")
' on récupère les données en une seule fois
plage = a.DataArray ' This is synonymous to a.getDataArray()
' on balaie l'ensemble de la plage pour mettre les valeurs dans un tableau
x=0
For Each ligne in plage
For Each valeur in ligne
tableau(x) = valeur
x = x + 1
Next valeur
Next ligne
Dim I%, J%, K%, tmp
For I = LBound(tableau) To UBound(tableau)
J = I
For K = J + 1 To UBound(tableau)
If tableau(K) >= tableau(J) Then J = K
Next K
If I <> J Then
tmp = tableau(J): tableau(J) = tableau(I): tableau(I) = tmp
End If
Next I
monDocument = ThisComponent
lesFeuilles = monDocument.Sheets
maFeuille = lesFeuilles.getByName("Feuille1")
ValRef = 0
Cmpt = 1
For i = 1 to x
if ValRef <> tableau(i) then
Cmpt = Cmpt + 1
ValRef = tableau(i)
end if
Next
ValRef = 0
j = Cmpt +20
For i = 0 to x-1
maCellule = maFeuille.getCellByPosition(1,j)
if ValRef <> tableau(i) then
maCellule.Value = tableau(i)
ValRef = tableau(i)
j = j-1
end if
Next
msgbox "Fin"
End Sub |
Partager