Classement de nombres
Bonjour à tous,
Je me retourne vers vous pour résoudre un petit soucis que je rencontre.
Je cherche simplement à faire un classement des nombres affichés en colonne 4 dans la colonne 2 quelques soit l'ordre.
J'ai essayé de procéder avec ce code mais rien ne se passe
Sub test()
Dim n, i As Integer
n = ThisWorkbook.Worksheets(1).Cells(Rows.Count, 3).End(xlUp).Row
For i = 3 To n
ThisWorkbook.Worksheets(1).Cells(i, 2).Value = WorksheetFunction.Rank(ThisWorkbook.Worksheets(1).Cells(i, 4).Value, ThisWorkbook.Worksheets(1).Cells(1, 4).Resize(1, n))
Next i
End SubJe vous remercie tous de votre précieuse aide
Bonjour,
A tester, mais attention au résultats
Option Explicit
Public Sub Rang_Plage()
Dim wS As Worksheet
Dim Plage As Range
Dim derLigne As Long
Dim i As Long
Set wS = ActiveSheet
derLigne = wS.Range("C" & Rows.Count).End(xlUp).Row
Set Plage = wS.Range(Cells(3, 4), Cells(derLigne, 4))
For i = 3 To derLigne
Cells(i, 2) = Application.WorksheetFunction.Rank(Cells(i, 4), Plage)
Next
Set wS = Nothing
End SubMerci beaucoup,
Le code fonctionne cependant je me suis aperçus que lorsque deux nombres sont les mêmes (dans notre exemple le nombre 23 apparaît deux fois), Excel attribut à ces derniers le même classement (ce qui est bien) mais en revanche le troisième plus grand nombre est classé 4èime (au lieu de troisième)
Existerait il un moyens de corriger cela?
Je suis en train de travailler sur un code du type:
Dim n, i As Integer
Dim rg As Range
n = ThisWorkbook.Worksheets(1).Cells(Rows.Count, 3).End(xlUp).Row
Set rg = ThisWorkbook.Worksheets(1).Cells(3, 3).Resize(1, n)
For i = 3 To n
If ThisWorkbook.Worksheets(1).Cells(i, 4).Value = WorksheetFunction.Large(rg, 1) Then ThisWorkbook.Worksheets(1).Cells(i, 2).Value = 1
If ThisWorkbook.Worksheets(1).Cells(i, 4).Value = WorksheetFunction.Large(rg, 2) Then ThisWorkbook.Worksheets(1).Cells(i, 2).Value = 2
If ThisWorkbook.Worksheets(1).Cells(i, 4).Value = WorksheetFunction.Large(rg, 3) Then ThisWorkbook.Worksheets(1).Cells(i, 2).Value = 3
If ThisWorkbook.Worksheets(1).Cells(i, 4).Value = WorksheetFunction.Small(rg, 2) Then ThisWorkbook.Worksheets(1).Cells(i, 2).Value = 4
If ThisWorkbook.Worksheets(1).Cells(i, 4).Value = WorksheetFunction.Small(rg, 1) Then ThisWorkbook.Worksheets(1).Cells(i, 2).Value = 5
Next iMais ça n'aboutit pas.
J'ai parvenue à faire ceci:
Dim n, i As Integer
Dim rg As Range
n = ThisWorkbook.Worksheets(1).Cells(Rows.Count, 3).End(xlUp).Row
Set rg = ThisWorkbook.Worksheets(1).Range(Cells(3, 4), Cells(n, 4))
For i = 3 To n
If ThisWorkbook.Worksheets(1).Cells(i, 4).Value = WorksheetFunction.Large(rg, 1) Then ThisWorkbook.Worksheets(1).Cells(i, 2).Value = 1
If ThisWorkbook.Worksheets(1).Cells(i, 4).Value = WorksheetFunction.Large(rg, 2) Then ThisWorkbook.Worksheets(1).Cells(i, 2).Value = 2
If ThisWorkbook.Worksheets(1).Cells(i, 4).Value = WorksheetFunction.Large(rg, 3) Then ThisWorkbook.Worksheets(1).Cells(i, 2).Value = 3
If ThisWorkbook.Worksheets(1).Cells(i, 4).Value = WorksheetFunction.Small(rg, 2) Then ThisWorkbook.Worksheets(1).Cells(i, 2).Value = 4
If ThisWorkbook.Worksheets(1).Cells(i, 4).Value = WorksheetFunction.Small(rg, 1) Then ThisWorkbook.Worksheets(1).Cells(i, 2).Value = 5
Next iMais j'ai le même souci, cette fois ci les nombres 23 sont classés 3ième au lieu de 2ième...
Ça me semble bizarre.