Any way to make this MACRO faster??

fisht

New Member
Joined
Sep 1, 2013
Messages
47
Hi all,

Can someone please take a look and hopefully figure out a way to speed up the execution of the following vba code?

Thank you in advance!

Code:

Sub Remove_Rows()


Sheets("Data").Activate
Dim LRow As Long, n As Long

LRow = Range("C1000000").End(xlUp).Row
For n = LRow To 1 Step -1
If Cells(n, 3).Value = "n/a" Then Cells(n, 3).EntireRow.Delete
Next n


End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
You can use AutoFilter, then Goto-->Special-->Visible cells only, then delete.

That's easily recordable, and it's a lot faster than looping.

HTH,
 
Upvote 0
Hi Smitty-

I actually need the rows to be removed by using a macro and not by filtering.. any ideas?



You can use AutoFilter, then Goto-->Special-->Visible cells only, then delete.

That's easily recordable, and it's a lot faster than looping.

HTH,
 
Upvote 0
Like I said, it's easily recordable.

Feel free to post what you get back here and someone can set it up dynamically.
 
Upvote 0
Smitty- sorry I am not quite following what you meant by "You can use AutoFilter, then Goto-->Special-->Visible cells only, then delete. That's easily recordable, and it's a lot faster than looping."

What would be the best way to 'record' this macro to delete the rows that only contain a "n/a" in column C?



Like I said, it's easily recordable.

Feel free to post what you get back here and someone can set it up dynamically.
 
Upvote 0
If you start recording a macro, you can apply AutoFilter to your range, then filter on n/a. From there you select the range and use Goto (F5)-->Special-->Visible cells only, which will select just the filtered n/a rows. Then you can delete the rows and just the n/a rows will be deleted. Then you can remove the filter and stop recording.
 
Upvote 0
Thanks for your response Smitty. I will try that out!

If you start recording a macro, you can apply AutoFilter to your range, then filter on n/a. From there you select the range and use Goto (F5)-->Special-->Visible cells only, which will select just the filtered n/a rows. Then you can delete the rows and just the n/a rows will be deleted. Then you can remove the filter and stop recording.
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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