更快地执行If语句的方法

时间:2018-05-31 14:11:21

标签: excel-vba performance if-statement vba excel

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

0 个答案:

没有答案