Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.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_Performance_If Statement_Vba - Fatal编程技术网

Excel 执行If语句的更快方法

Excel 执行If语句的更快方法,excel,performance,if-statement,vba,Excel,Performance,If Statement,Vba,有没有更快的方法来运行下面的代码?“hr”工作表有24000行,运行这个简单的查询大约需要30多分钟 Sub populateHRData17() 'APAC Set report = ActiveWorkbook.Worksheets("Report") Set hr = ActiveWorkbook.Worksheets("HR_Report") Set apac = ActiveWorkbook.Worksheets("APAC_L_R") For x = 2 To report.Use

有没有更快的方法来运行下面的代码?“hr”工作表有24000行,运行这个简单的查询大约需要30多分钟

Sub populateHRData17()
'APAC
Set report = ActiveWorkbook.Worksheets("Report")
Set hr = ActiveWorkbook.Worksheets("HR_Report")
Set apac = ActiveWorkbook.Worksheets("APAC_L_R")

For x = 2 To report.UsedRange.Rows.Count
    If report.Cells(x, 1) = "" Then
    End If
Next x


For i = 2 To hr.UsedRange.Rows.Count
  For j = 2 To apac.UsedRange.Rows.Count

    If apac.Cells(j, 2) = hr.Cells(i, 3) Then
       report.Cells(x, 1) = apac.Cells(j, 2)


 x = x + 1
    End If

Next j
Next i
End Sub

使用变量数组存储数据并循环这些数据。限制vba需要引用工作表上数据的次数,您将看到一个很大的改进。第一个循环的目的是什么,我看不到其中的任何逻辑。您可以使用,而不是使用第一个循环来查找“报告”工作表中的最后一行<代码>工作表(“报告”)。单元格(工作表(“报告”)。行数,“A”)。结束(xlUp)。偏移量(1)。值=亚太区。单元格(j,2)。值我将查看变量数组。还是有点新鲜谢谢!Dave我尝试了你给我的代码,但是我得到了一个“应用程序定义的或对象定义的错误”