Excel VBA 按降序对数字数组进行排序的最快方法? [英] Excel VBA Quickest way to sort an array of numbers in descending order?

查看:41
本文介绍了Excel VBA 按降序对数字数组进行排序的最快方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按降序对数字数组(1000-10000 个数字,但可能会有所不同)进行排序的最快方法(就计算时间而言)是什么?据我所知,Excel 内置函数并不是很有效,内存排序应该比 Excel 函数快很多.

What is the quickest way (in terms of computational time) to sort an array of numbers (1000-10000 numbers but could vary) in descending order? As far as I know the Excel build-in functions is not really efficient and in-memory sorting should be a lot faster than the Excel functions.

请注意,我无法在电子表格上创建任何内容,所有内容都必须仅在内存中存储和排序.

Note that I can not create anything on the spreadsheet, everything has to be stored and sorted in memory only.

推荐答案

您可以使用 System.Collections.ArrayList:

You could use System.Collections.ArrayList:

Dim arr As Object
Dim cell As Range

Set arr = CreateObject("System.Collections.ArrayList")

' Initialise the ArrayList, for instance by taking values from a range:
For Each cell In Range("A1:F1")
    arr.Add cell.Value
Next

arr.Sort
' Optionally reverse the order
arr.Reverse

这里使用快速排序.

这篇关于Excel VBA 按降序对数字数组进行排序的最快方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆