macro to delete rows that do not contain a 6 digit number

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,603
Office Version
  1. 2021
Platform
  1. Windows
I have mainly 6 digit numbers in Col B on sheet2


I need code that will delete all rows from row 2 onwards where there is not a 6 digit number in Col B


See sample data below. I want all the rows to be deleted from row 2 where there is no 6 digit number



Book1
B
2933808
3933750
4933752
5933910
6935050
7Short Des
8Fact
9Disc
10COS
11Not in use
12933815
13933816
14933845
15Sales Item1
16933872
17933801
18
Sheet1
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
something like this?

Code:
Sub DelRow()


LastRowNo = Worksheets("Sheet1").Cells(Rows.Count, "B").End(xlUp).Row


For RowLoop = LastRowNo To 2 Step -1
    If Worksheets("Sheet1").Range("B" & RowLoop).Value < 100000 Or IsNumeric(Worksheets("Sheet1").Range("B" & RowLoop).Value) = False Then
        Rows(RowLoop & ":" & RowLoop).Delete
    End If
Next RowLoop
End Sub
 
Upvote 0
How about
Code:
Sub delRows()
   With Range("B2", Range("B" & Rows.Count).End(xlUp))
      .Value = Evaluate(Replace("if((isnumber(@))*(len(@)=6),@,"""")", "@", .Address))
      .SpecialCells(xlBlanks).EntireRow.Delete
   End With
End Sub
 
Upvote 0
Thanks for the help guys. Code works perfectly
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
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