I'm trying to sort a column of 7 values starting in cell A40, and ending in A46. I am using a bubble sort and I create two procedure. However, when I execute, VBA tells me the subscript is out of range... Would anyone be able to tell me where is the problem in my code, please?
Sub dort()
Dim plaga() As Variant
plaga = Worksheets("Sheet3").Range("A40:A46").Value
Call tri1(plaga)
Dim Destination As Range
Set Destination = Worksheets("Sheet3").Range("C40")
Destination.Resize(7, 1).Value = plaga
End Sub
Sub tri1(plaga As Variant)
Dim ligne_Deb As Long
Dim ligne_Fin As Long
ligne_Deb = LBound(plaga)
ligne_Fin = UBound(plaga)
Dim i As Long, j As Long
Dim tmp As Long
For i = ligne_Deb To ligne_Fin - 1
For j = ligne_Fin To i + 1 Step -1
If plaga(j) < plaga(j - 1) Then
tmp = plaga(j)
plaga(j) = plaga(j - 1)
plaga(j - 1) = tmp
End If
Next j
Next i
End Sub
Sortobject? keep in mind that your procedure is inefficient