Sub Macro1()
Dim arr, i, rng As Range
arr = Array("X", "Y", "Z")
Set rng = ActiveSheet.Range("A1").CurrentRegion
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
For i = LBound(arr) To UBound(arr)
rng.Replace What:=arr(i), Replacement:="-", LookAt:=xlWhole, _
SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
ReplaceFormat:=False
Next i
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
End Sub
編輯:
Sub KeepValues()
Dim arr, arrVals, i, rng As Range, r, c
Dim keepval As Boolean
arr = Array("X", "Y", "Z")
Set rng = ActiveSheet.Range("A1").CurrentRegion
arrVals = rng.Value
For r = 1 To UBound(arrVals, 1)
For c = 1 To UBound(arrVals, 2)
keepval = False
For i = LBound(arr) To UBound(arr)
If arr(i) = arrVals(r, c) Then
keepval = True
Exit For
End If
Next i
If Not keepval Then arrVals(r, c) = ""
Next c
Next r
rng.Value = arrVals
End Sub
你寫過代碼,它是慢?我預計它會很快。 –
是的,我使用循環技術。這是我粘貼在這裏的一個特殊的快照。實際工作表有3500行和250列,這使得它更慢。所以我想知道任何最快的過程。 –
你可以發佈你使用的代碼嗎? –