Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello,
I need to sort a table with BubbleSort. I know how the algorithm works: For i = left To right - 1 If student_temp(i) student_temp(i + 1) Then Call swap(i, i + 1) End If Private Sub swap Dim hold As String hold = student_temp(j) student_temp(j) = student_temp(k) student_temp(k) = hold but I have no idea how this works on an Excel sheet. How do I access the rows? Do I need an array? I will appreciate any help. Thanks in advance --- Message posted from http://www.ExcelForum.com/ |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Why do you need the bubble sort, why not use Excel's built-in sort?
-- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "CGeorges " wrote in message ... Hello, I need to sort a table with BubbleSort. I know how the algorithm works: For i = left To right - 1 If student_temp(i) student_temp(i + 1) Then Call swap(i, i + 1) End If Private Sub swap Dim hold As String hold = student_temp(j) student_temp(j) = student_temp(k) student_temp(k) = hold but I have no idea how this works on an Excel sheet. How do I access the rows? Do I need an array? I will appreciate any help. Thanks in advance --- Message posted from http://www.ExcelForum.com/ |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
One way is to put the range data into an array, perform the sort, then put the data back again. Something like. Sub aaa() Dim arr As Variant arr = Range("a1:f1").Value For i = LBound(arr, 2) To UBound(arr, 2) - 1 For j = i + 1 To UBound(arr, 2) If arr(1, i) arr(1, j) Then holder = arr(1, i) arr(1, i) = arr(1, j) arr(1, j) = holder End If Next j Next i Range("a1:f1").Value = arr End Sub Tony ----- CGeorges wrote: ----- Hello, I need to sort a table with BubbleSort. I know how the algorithm works: For i = left To right - 1 If student_temp(i) student_temp(i + 1) Then Call swap(i, i + 1) End If Private Sub swap Dim hold As String hold = student_temp(j) student_temp(j) = student_temp(k) student_temp(k) = hold but I have no idea how this works on an Excel sheet. How do I access the rows? Do I need an array? I will appreciate any help. Thanks in advance --- Message posted from http://www.ExcelForum.com/ |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Pivot Table sort -Excel 2007 | Excel Discussion (Misc queries) | |||
How do I sort a table by last name and first name in Excel? | Setting up and Configuration of Excel | |||
How import table and have Excel sort automatically? | Excel Discussion (Misc queries) | |||
When I try to sort in Excel only part of the table sorts | Excel Discussion (Misc queries) | |||
how do i sort a table in excel | Excel Worksheet Functions |