首页 > 解决方案 > 执行 If 语句的更快方法

问题描述

有没有更快的方法来运行下面的代码?“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

标签: excelperformanceif-statementvba

解决方案


推荐阅读