Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 将值读入数组直到满足条件_Vba - Fatal编程技术网

Vba 将值读入数组直到满足条件

Vba 将值读入数组直到满足条件,vba,Vba,我在C3-CX列的excel文件中有值。也就是说,我有任意数量的行。现在我想将这些值读入数组,问题是每一行都是空的,我不想在数组中包含空的空间,所以在字段为空之前我不能执行while循环。你将如何解决这个问题?假设我想将第一列中的数据读入一个数组。[测试,测试] (Col C:2) (Col D:2) testa test2 test teste test test 像下面这样的方法应该可以奏效 Funct

我在C3-CX列的excel文件中有值。也就是说,我有任意数量的行。现在我想将这些值读入数组,问题是每一行都是空的,我不想在数组中包含空的空间,所以在字段为空之前我不能执行while循环。你将如何解决这个问题?假设我想将第一列中的数据读入一个数组。[测试,测试]

    (Col C:2) (Col D:2)
    testa   test2
            test
    teste   test
            test

像下面这样的方法应该可以奏效

    Function read_array(inputRange As Range) As String()
    Dim element_count As Integer, i As Integer

    element_count = Application.WorksheetFunction.CountA(inputRange)
    ReDim outArray(1 To element_count) As String
    y = 1
    For i = 1 To element_count

    Do While IsEmpty(inputRange(y))
    y = y + 1
    Loop
    outArray(i) = inputRange(y)
    y = y + 1
    Next
    read_array = outArray
    End Function

您可以将其称为read_数组(c:c)。输出将是一个行数组。

然后向后迭代数组并删除空数组。您不排序范围吗?这是一种消除空行的简单方法。