On Apr 19, 5:40 pm, Joel <J...@discussions.microsoft.com> wrote:
> Private Sub CommandButton1_Click()
> Dim i, j As Integer
> Dim MyArray As Variant
>
> Sheets("InsertCustomerPostcode").Range("B3") = TextBox1
> Sheets("InsertCustomerPostcode").Range("B8") = Val(TextBox2)
> ListBox1.ColumnWidths = _
> "100; 125; 125; 125; 100; 80; 50; 40; 50;50"
>
> j = 2
> Count = 0
> k = Cells(j, 2)
>
> Do Until k = ""
> Count = Count + 1
> j = j + 1
> k = Cells(j, 2)
> Loop
>
> ReDim MyArray(Count, 8)
>
> i = 0
> j = 2
> k = Cells(j, 2)
>
> Do Until k = ""
> MyArray(i, 0) = Cells(j, 3) ' Supplier
> MyArray(i, 1) = Cells(j, 4) ' Supplier
> MyArray(i, 2) = Cells(j, 5) ' Supplier
> MyArray(i, 3) = Cells(j, 6) ' Supplier
> MyArray(i, 4) = Cells(j, 8) ' Supplier
> MyArray(i, 5) = Cells(j, 9) ' Supplier
> MyArray(i, 6) = Cells(j, 2) ' Postcode
> MyArray(i, 7) = Round(Cells(j, 10), 2) ' Distance
> MyArray(i, 8) = Cells(j, 11) ' Within Radius?
> i = i + 1
> j = j + 1
> k = Cells(j, 2)
> Loop
>
> For x = 0 To (Count - 2)
>
> For y = 1 To (Count - 1)
>
> If MyArray(x, 8) > MyArray(y, 8) Then
>
> For z = 1 To 8
>
> temp = MyArray(x, z)
> MyArray(x, z) = MyArray(y, z)
> MyArray(y, z) = temp
>
> Next z
>
> End If
> Next y
> Next x
> ListBox1.List = MyArray
>
> End Sub
>
>
>
> "s...@gemsi.plus.com" wrote:
> > Hi there,
>
> > I've got a pretty simple array that is populating on a form. I need
> > some way of sorting the data by 'radius' before it hits the form, can
> > anyone help?
>
> > My code is:
>
> > Private Sub CommandButton1_Click()
> > Dim i, j As Integer
> > Dim MyArray As Variant
>
> > Sheets("InsertCustomerPostcode").Range("B3") = TextBox1
> > Sheets("InsertCustomerPostcode").Range("B8") = Val(TextBox2)
> > ListBox1.ColumnWidths = "100; 125; 125; 125; 100; 80; 50; 40; 50;
> > 50"
>
> > j = 2
> > Count = 0
> > k = Cells(j, 2)
>
> > Do Until k = ""
> > Count = Count + 1
> > j = j + 1
> > k = Cells(j, 2)
> > Loop
>
> > ReDim MyArray(Count, 8)
>
> > i = 0
> > j = 2
> > k = Cells(j, 2)
>
> > Do Until k = ""
> > MyArray(i, 0) = Cells(j, 3) ' Supplier
> > MyArray(i, 1) = Cells(j, 4) ' Supplier
> > MyArray(i, 2) = Cells(j, 5) ' Supplier
> > MyArray(i, 3) = Cells(j, 6) ' Supplier
> > MyArray(i, 4) = Cells(j, 8) ' Supplier
> > MyArray(i, 5) = Cells(j, 9) ' Supplier
> > MyArray(i, 6) = Cells(j, 2) ' Postcode
> > MyArray(i, 7) = Round(Cells(j, 10), 2) ' Distance
> > MyArray(i, 8) = Cells(j, 11) ' Within Radius?
> > i = i + 1
> > j = j + 1
> > k = Cells(j, 2)
> > Loop
>
> > ListBox1.List = MyArray
>
> > End Sub- Hide quoted text -
>
> - Show quoted text -
Thank you! I shall try this today!