找到具有specfic值的单元格并删除其下方的选定数组

时间:2018-05-08 15:11:58

标签: excel vba excel-vba

我有一个跨越BL3:CW10000的公式数组,它使用字母数字字符串的综合列表(长度在1000-2000个条目之内)。计算完成后,结果值将复制到另一个工作表。我试图在两个选项之间做出决定:

  1. 让公式数组“固定”,每个单元格下载到第10000行,然后删除#REF!复制/粘贴值产生的结果(此数组是问题标题所指的)。

  2. 让VBA将其指定列中的每个公式自动填充到合并列表范围中条目数指定的长度。 哪种方式最适合速度?

1 个答案:

答案 0 :(得分:0)

我需要设置自己的样本数据和代码来测试任一选项的时间,这需要很长时间。但是(假设您已经获得了两个选项的代码),在您的最终得到这些信息应该相当简单。

创建一个调用子(见下文),打开即时窗口,然后运行调用子查看结果。

Sub Timer_Test()

    Dim dTime as Double

    dTime = Timer

    Call Relevant_Sub_or_Function_One

    Debug.Print "descriptive text (method One)" & Timer - dTime
    dTime = Timer

    Call Relevant_Sub_or_Function_Two

    Debug.Print "descriptive text (method Two)" & Timer - dTime

End Sub

如果两种方法运行得太快且结果没有帮助,请设置如下所示的循环。 (注意:如果方法需要一段时间,你应该从一个较小的循环数开始,比如100左右,并根据需要进行构建)

Sub Timer_Test()
    Dim counter as Long
    Dim dTime as Double

    dTime = Timer

    For counter = 1 to 10000 ' Or whatever value you deem appropriate...
        Call Relevant_Sub_or_Function_One
        DoEvents 'optional, keeps Excel from crashing, but you shouldn't attempt to use Excel while this is running, or the results will be skewed...
    Next counter

    Debug.Print "descriptive text (method One)" & Timer - dTime
    dTime = Timer

    For counter = 1 to 10000 ' Or whatever value you deem appropriate...
        Call Relevant_Sub_or_Function_Two
        DoEvents 'optional, keeps Excel from crashing, but you shouldn't attempt to use Excel while this is running, or the results will be skewed...
    Next counter

    Debug.Print "descriptive text (method Two)" & Timer - dTime

End Sub