VBA-Loop并填充缺失的数据

时间:2018-02-21 12:46:55

标签: excel-vba vba excel

我正在创建一个宏,它在工作表中循环以获取特定值,然后填充另一个工作表中提到的缺失数据 代码工作正常,但问题是花费太多时间来填充缺失值,有时excel文件没有响应,这迫使我再次重复整个事情

我的代码:

Sub TraiterNoms()
  Application.ScreenUpdating = False
  Application.DisplayAlerts = False
  Dim i As Variant
  Dim CompareRange As Variant
  Dim x As Variant
  Dim y As Variant
  Dim derlignE As Variant
  Dim derlignC As Variant


  derlignE = Range("A" & Rows.Count).End(xlUp).Row
  derlignC = Sheets("Feuil1").Range("C" & Rows.Count).End(xlUp).Row
  Set CompareRange = Sheets("Feuil1").Range("A:A")

  For i = Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1
    If Range("B" & i) = "" Then
      For Each x In Range("A:A")
        For Each y In CompareRange
          If x = y Then x.Offset(0, 1) = y.Offset(0, 1)
        Next y
      Next x
    End If
  Next i
  Application.ScreenUpdating = True
  Application.DisplayAlerts = True
End Sub

任何人都可以点亮我关于优化此代码的信息

0 个答案:

没有答案