Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.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/0/vba/15.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
Excel 带有大文件循环的数组或If语句。当在一个小文件中测试时,代码可以工作_Excel_Vba - Fatal编程技术网

Excel 带有大文件循环的数组或If语句。当在一个小文件中测试时,代码可以工作

Excel 带有大文件循环的数组或If语句。当在一个小文件中测试时,代码可以工作,excel,vba,Excel,Vba,目的:让我的代码查看第4列,找到“示例1”或“示例2”或“示例3”,然后将单个值返回到第29列的另一个单元格中。例如,D3是“示例3”,AC3是“值”,D1839是“示例1”,AC1839是“值” 这是我的密码 FinalRow = Cells(Rows.Count, 1).End(xlUp).Row For x = 1 To FinalRow If Cells(x, 4) = "Example 1" Or Cells(x, 4) = "Example

目的:让我的代码查看第4列,找到“示例1”或“示例2”或“示例3”,然后将单个值返回到第29列的另一个单元格中。例如,D3是“示例3”,AC3是“值”,D1839是“示例1”,AC1839是“值”

这是我的密码

    FinalRow = Cells(Rows.Count, 1).End(xlUp).Row

        For x = 1 To FinalRow

        If Cells(x, 4) = "Example 1" Or Cells(x, 4) = "Example 2" Or Cells(x, 4) = "Example 3" _ 
 Or Cells(x, 4) = "Example 4" Or Cells(x, 4) = "Example 5" _
 Or Cells(x, 4) = "Example 6" Then Cells(x, 29) = "AP"
        Next x
奇怪的是,当我在一个小样本上尝试它时,它就工作了,即一个只有第4列和第29列的新表单

我正在寻求帮助,寻找一种让代码工作的方法。用于65000行和180个示例


谢谢你的帮助。我希望我的问题是清楚的。

在数组中循环,并在列AC中构建单元的并集

Dim arr As Variant, i As Long, rng As Range

arr = Range(Cells(1, "D"), Cells(Rows.Count, "D").End(xlUp)).Value

For i = LBound(arr, 1) To UBound(arr, 1)

    Select Case arr(i, 1)
        Case "Example 1", "Example 2", "Example 3", "Example 4", "Example 5", "Example 6"
            If rng Is Nothing Then
                Set rng = Cells(i, "AC")
            Else
                Set rng = Union(rng, Cells(i, "AC"))
            End If
        Case Else
            'do nothing
    End Select

Next i

If Not rng Is Nothing Then
    rng = "AP"
End If