vba - Excel VBA排序数组函数

标签 vba excel

我已经编写了下面显示的函数。当我在 Sub 中使用它时它可以工作。这是我第一次尝试编写函数。我知道这是一个菜鸟问题,但是我似乎无法运行该功能。这可能与未正确调用函数或未正确定义函数头中的变量有关

谁能指出我正确的方向。

Function SortArray(ArrayToSort As String)
    Dim x As Long, y As Long
    Dim TempTxt1 As String
    Dim TempTxt2 As String

    For x = LBound(ArrayToSort) To UBound(ArrayToSort)
        For y = x To UBound(ArrayToSort)
            If UCase(ArrayToSort(y)) < UCase(ArrayToSort(x)) Then
                TempTxt1 = ArrayToSort(x)
                TempTxt2 = ArrayToSort(y)
                ArrayToSort(x) = TempTxt2
                ArrayToSort(y) = TempTxt1
            End If
        Next y
    Next x
End Function


Sub CreateUniquesList()
    Dim References() As String
    ...
    SortArray (References)
    ...
End Sub

最佳答案

添加括号以确保参数是一个数组

Function SortArray(ArrayToSort() As String)
    'your code
End Function

Sub CreateUniquesList()
    Dim References() As String
    '...
    SortArray References 'lose the parentheses
    '...
End Sub

关于vba - Excel VBA排序数组函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44077753/

相关文章:

excel - 当用户在 MS Access VBA 中的参数请求输入框中点击取消时如何获取返回值?

excel - 从所有工作表中复制范围并将它们粘贴到新的工作表中

vba - 如何通过 VBA 连接到 Lotus Notes 数据库?

java - 为什么我收到错误 SQLException : [Microsoft][ODBC Excel Driver] Too few parameters. Expected 1

vba - Excel VBA : How to push data to an exclusive range on another sheet?

VBA Microsoft.XMLHTTP setRequestHeader 不发送 cookie

excel - 用excel(vba)中的字符串排序修复

excel - 如何确定单元格中是否已写入公式或手动输入

excel - For 循环遍历一行

vba - 后期绑定(bind) IHTML 元素