How to delete row based on cell value?

Routus

New Member
Joined
Mar 7, 2019
Messages
15
Office Version
  1. 2021
Platform
  1. Windows
Hi all
I'm about to record a macro, which although lengthy is mostly straight forward, however there is one element I will have to add in some manual code, and I need advice please.

Column AA in my worksheet has a mix of cells, and I need to identify the non-numeric cells and delete the full row that holds those cells. e.g. cell AA6 holds a non-numeric value, so I need to delete row 6 completely.

Any help appreciated

Thank you
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
About how many rows of data altogether in your worksheet?
Hundreds of thousands?
Tens of thousands?
Thousands?
Hundreds?
Less?
 
Upvote 0
About how many rows of data altogether in your worksheet?
Hundreds of thousands?
Tens of thousands?
Thousands?
Hundreds?
Less?
Hi Peter

There will eventually be around 200,000, but at the moment I am building my method using just a few hundred rows
 
Upvote 0
There will eventually be around 200,000,
Some methods that will work quite well with a few hundred rows will completely bog down with 200,000.

Assuming a header row and no dates or blank cells in column AA try this with a copy of your data.
If my assumptions are incorrect, please give more details, or better still, some sample data with XL2BB that shows what variety that might be in col AA

VBA Code:
Sub Del_Non_Numeric()
  Dim a As Variant, b As Variant
  Dim nc As Long, i As Long, k As Long
 
  nc = Cells.Find(What:="*", LookIn:=xlFormulas, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column + 1
  a = Range("AA2", Range("AA" & Rows.Count).End(xlUp)).Value
  ReDim b(1 To UBound(a), 1 To 1)
  For i = 1 To UBound(a)
    If Not IsNumeric(a(i, 1)) Then
      b(i, 1) = 1
      k = k + 1
    End If
  Next i
  If k > 0 Then
    Application.ScreenUpdating = False
    With Range("A2").Resize(UBound(a), nc)
      .Columns(nc).Value = b
      .Sort Key1:=.Columns(nc), Order1:=xlAscending, Header:=xlNo
      .Resize(k).EntireRow.Delete
    End With
    Application.ScreenUpdating = True
  End If
End Sub
 
Upvote 1
Solution

Forum statistics

Threads
1,224,813
Messages
6,181,118
Members
453,021
Latest member
Justyna P

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