VBA how to delete rows when a number is in a cell

cazdealer

Board Regular
Joined
Mar 12, 2011
Messages
96
Hi,
I want to find a way to create a VBA procedure that will delete all rows that have a number or part of a number in the string in column A.

I have data from A1 to A1000.

For exemple, if this is in the first cell of the row (A), I want the full row to be deleted:
ex: AAA1, 100.93, 10, 1A1, fedex1, 123, q0q


How could I go that?
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
So you're saying if the first cell contains a digit (0-9), then delete the row?

Do you have headers in row 1?
 
Upvote 0
Yes exactly, if this is a digit from 0 to 9 in cell A (even if it's combine with letters), I want that full row to be deleted...

no, there is no headers

it starts at A1

thanks
 
Upvote 0
try this (on a copy of your data first...)

Code:
Sub deleteRowIfDigit()
    lr = Cells(Rows.Count, "A").End(xlUp).Row
    With CreateObject("VBScript.RegExp")
        .Pattern = "\d"
        For r = lr To 1 Step -1
            If .test(Cells(r, "A")) Then Rows(r).EntireRow.Delete
        Next
    End With
End Sub
 
Upvote 0
Perfect! works like a charm!

one question: what is the .Pattern = "\d" does?
first time I see something like that?
 
Upvote 0

Forum statistics

Threads
1,224,594
Messages
6,179,792
Members
452,942
Latest member
VijayNewtoExcel

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