Delete row if range of cells contain specific digits

sakis_s

New Member
Joined
Sep 22, 2019
Messages
39
Office Version
  1. 2016
Platform
  1. Windows
Hi & happy new year!

I have some rows looking like this:
145212
011101
10101
01111
410143

What i need is a way to run a macro where it finds the rows in range A:E that contain only combination of "0" and "1" in any sequence and then deleting these rows and shift the deleted rows up.
In my example above it should delete rows 3 and 4.

Has anyone any idea how to do this? I really appreciate your help.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Hi Sakis_s
This should do the trick

Code:
Sub DeleteBitRows()
    Dim Matrix, Cell As Range
    Set Matrix = Sheet1.Range("A1:A5")
    With Sheet1
        For Row = 1 To 6
            If .Cells(Row, 1).Value = "" Then Exit For
            For Currentcol = 1 To 5
                If .Cells(Row, Currentcol) <> 0 And _
                    .Cells(Row, Currentcol) <> 1 Then
                    Exit For
                ElseIf Currentcol = 5 Then
                    If .Cells(Row, Currentcol) = 0 Or _
                        .Cells(Row, Currentcol) = 1 Then
                            .Cells(Row, Currentcol).EntireRow.Delete xlUp
                            Row = Row - 1
                    End If
                End If
            Next Currentcol
        Next Row
    End With
End Sub
[code]

Excel Fun
 
Upvote 0
Solution
Hi Sakis_s
This should do the trick

Code:
Sub DeleteBitRows()
    Dim Matrix, Cell As Range
    Set Matrix = Sheet1.Range("A1:A5")
    With Sheet1
        For Row = 1 To 6
            If .Cells(Row, 1).Value = "" Then Exit For
            For Currentcol = 1 To 5
                If .Cells(Row, Currentcol) <> 0 And _
                    .Cells(Row, Currentcol) <> 1 Then
                    Exit For
                ElseIf Currentcol = 5 Then
                    If .Cells(Row, Currentcol) = 0 Or _
                        .Cells(Row, Currentcol) = 1 Then
                            .Cells(Row, Currentcol).EntireRow.Delete xlUp
                            Row = Row - 1
                    End If
                End If
            Next Currentcol
        Next Row
    End With
End Sub
[code]

Excel Fun
This works perfectly! Thank you so much for your time, i really appreciate it!
I wish you the best!
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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