-1

我需要在很大范围内(超过 1000 行)清除单元格值“noinfo”。我使用下面提到的宏,但是速度很慢。也许有更好的方法来执行这项任务?

For Each cell In Range("L2:N" & Range("N" & Rows.count).End(xlUp).Row)
    If cell.Value = "noinfo" Then cell.ClearContents
Next cell
4

1 回答 1

0

我发现将所有值复制到数组、更改数组并立即将它们写入范围要快得多。

Dim values(), r As Long, c As Long
With Range("L2:N" & Range("N" & Rows.Count).End(xlUp).Row)
    values = .Value
    For r = 1 To UBound(values, 1)
        For c = 1 To UBound(values, 2)
             If values(r, c) = "noinfo" Then values(r, c) = Empty
        Next
    Next
    .Value = values
End With

优点:

  • 在您写入所有值之前,不会进行屏幕更新或计算;
  • 使用内在数据,而不是属性。
于 2013-08-23T08:27:50.683 回答