Craig Moran wrote:
Regardless, I’d like to know how someone else would implement this in a
more Rubyish manner. Keep in mind two things:
- The Move function always places the moved worksheet before the
target worksheet and not after.
- Any moved worksheet will change the indexes of other worksheets.
Okay, then. If all the worksheet names are unique, simply read all the
worksheet names, then sort them in Ruby:
“reverse” because the sheets will be inserted at the beginning of the
which means the last item in the array ends up in the first position.
Then write a routine that moves them in sort order to the beginning of
array.each do |sheet_name|
move each sheet from wherever it is now to the beginning of the stack
This would be easier to understand later on, and it’s more efficient as
number of worksheets increases. Also, because you are presently moving
worksheets as the sort proceeds, it is much slower than simply sorting
names, which increases the burden created by the bubble sort.
The name sort would be performed at high speed, then the sheets would be
moved just once at the end of the sort. Much faster, and less
Umm, on re-reading your post, I must ask whether the sheets can be
to by name. If not, this becomes a bit more difficult, but it is still