'Option Explicit
Option Compare Text
Sub ValeurX() 'axe des abscisses
Dim Tbl()
Dim d As Object
Dim WS1 As Worksheet
Dim RGX As Range 'Colonne pour les X
Dim FIN As Integer
Dim i As Long
Set WS1 = Sheets("EXERCICE 1")
Set RGX = WS1.Range("AS11")
FIN = WS1.Range("H12").Value
Set d = CreateObject("scripting.dictionary")
d.CompareMode = vbTextCompare
For i = 1 To FIN / 0.25
d.Add i, i * 0.25
Next i
d.Add d.Count + 1, WS1.Range("AO4")
d.Add d.Count + 2, WS1.Range("AO5")
DicoTriKeysVal d, 2
Tbl = d.items
'Transfert sur la feuille
[B1].Value = 0
'[B2].Resize(d.Count) = Application.Transpose(Tbl) 'Fonctionne aussi
[B2].Resize(d.Count) = Application.Transpose(d.items)
End Sub
Sub DicoTriKeysVal(dico, colTri)
Dim i
Dim c
Dim Tbl(): ReDim Tbl(1 To dico.Count, 1 To 2)
i = 0
For Each c In dico.keys
i = i + 1
Tbl(i, 1) = c: Tbl(i, 2) = dico(c)
Next c
Tri Tbl, LBound(Tbl), UBound(Tbl), colTri
dico.RemoveAll
For i = LBound(Tbl) To UBound(Tbl)
dico(Tbl(i, 1)) = Tbl(i, 2)
Next i
End Sub
Sub Tri(a, gauc, droi, colTri) ' Quick sort
ref = a((gauc + droi) \ 2, colTri)
g = gauc: d = droi
Do
Do While a(g, colTri) < ref: g = g + 1: Loop
Do While ref < a(d, colTri): d = d - 1: Loop
If g <= d Then
temp = a(g, 1): a(g, 1) = a(d, 1): a(d, 1) = temp
temp = a(g, 2): a(g, 2) = a(d, 2): a(d, 2) = temp
g = g + 1: d = d - 1
End If
Loop While g <= d
If g < droi Then Call Tri(a, g, droi, colTri)
If gauc < d Then Call Tri(a, gauc, d, colTri)
End Sub