Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA - Sort a table with BubbleSort

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Excel VBA - Sort a table with BubbleSort

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Excel VBA - Sort a table with BubbleSort

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pivot Table sort -Excel 2007 Lisa F Excel Discussion (Misc queries) 4 November 6th 08 11:37 PM
How do I sort a table by last name and first name in Excel? Kubbybear18 Setting up and Configuration of Excel 2 December 2nd 06 02:47 PM
How import table and have Excel sort automatically? Kristina Margarita Excel Discussion (Misc queries) 0 September 15th 06 05:28 PM
When I try to sort in Excel only part of the table sorts jrw562 Excel Discussion (Misc queries) 6 March 5th 06 08:31 PM
how do i sort a table in excel trey braid Excel Worksheet Functions 5 January 26th 06 03:55 AM


All times are GMT +1. The time now is 08:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"