VBA Code to delete rows based on cell data

esmecat

New Member
Joined
May 5, 2010
Messages
19
Hi,

I have some code which has worked for one workbook but is not working for another. It returns the data I want in Column G but also leaves a load of 0's which don't delete. Any help appreciated.



Sheets("Data Tab").Select

Dim Route As String

Application.ScreenUpdating = False

With Sheets("Data Tab")

Route = "G2:G" & Cells(Rows.Count, "G").End(xlUp).Row

Range(Route) = Evaluate(Replace("IF(@=""Anglia"",""#N/A"",@)", "@", Route))

Range(Route) = Evaluate(Replace("IF(@=""Central"",""#N/A"",@)", "@", Route))

Range(Route) = Evaluate(Replace("IF(@=""Kent"",""#N/A"",@)", "@", Route))

Range(Route) = Evaluate(Replace("IF(@=""London North Western (LNW)"",""#N/A"",@)", "@", Route))

Range(Route) = Evaluate(Replace("IF(@=""No Route Defined"",""#N/A"",@)", "@", Route))

Range(Route) = Evaluate(Replace("IF(@=""National/Project"",""#N/A"",@)", "@", Route))

Range(Route) = Evaluate(Replace("IF(@=""North West"",""#N/A"",@)", "@", Route))

Range(Route) = Evaluate(Replace("IF(@=""Scotland"",""#N/A"",@)", "@", Route))

Range(Route) = Evaluate(Replace("IF(@=""South East"",""#N/A"",@)", "@", Route))

Range(Route) = Evaluate(Replace("IF(@=""Sussex"",""#N/A"",@)", "@", Route))

Range(Route) = Evaluate(Replace("IF(@=""Wales"",""#N/A"",@)", "@", Route))

Range(Route) = Evaluate(Replace("IF(@=""Wessex"",""#N/A"",@)", "@", Route))

Range(Route) = Evaluate(Replace("IF(@=""West Coast Mainline South"",""#N/A"",@)", "@", Route))

Range(Route) = Evaluate(Replace("IF(@=""Western"",""#N/A"",@)", "@", Route))

Range(Route) = Evaluate(Replace("IF(@=""0"",""#N/A"",@)", "@", Route))

On Error GoTo NoDeletes

Columns("G").SpecialCells(xlConstants, xlErrors).EntireRow.Delete

End With

NoDeletes:

Application.ScreenUpdating = True
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Why not use replace instead
VBA Code:
   With Sheets("Data Tab")
      With .Range("G2", .Range("G" & Rows.Count).End(xlUp))
         .Replace "Anglia", "#N/A", xlWhole, , False, , False, False
         .Replace "Central", "#N/A", xlWhole, , False, , False, False
      End With
   End With
You could also put all the words to be replaced in an array & then loop that, rather than writing a separate replace for each.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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