VBA Fastest Way to Clear Cells

anthonyexcel

Active Member
Joined
Jun 10, 2011
Messages
258
Office Version
  1. 365
Platform
  1. Windows
Good afternoon,

Can someone please show me the fastest wat to clear all cells except for the value EXT. I have been using the code below but it is taking forever!

Code:
Sub moveit()
For Each cell In Selection
    If cell.Value <> "EXT" Then cell.Clear
Next
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Are the cells literal text or the result of formula?

What about the other cells in the column?

Assuming it's all just text,

Code:
Sub moveit()
    Dim av As Variant
    Dim i As Long
    
    With Intersect(Selection, ActiveSheet.UsedRange)
        av = .Value
        For i = 1 To UBound(av)
            If av(i, 1) <> "EXT" Then av(i, 1) = Empty
        Next i
        .Value = av
    End With
End Sub
 
Last edited:
Upvote 0
Code:
Sub keepEXT()
With Selection
    .Value = Evaluate("If(" & .Address & "=""EXT"",""EXT"","""")")
End With
End Sub
 
Upvote 0
shg,

Appreciate it, you are right it is just text! mirabeau that you also for your approach!
 
Upvote 0
You're welcome, glad it worked for you.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,287
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top