must remove first character of cell if not #3Created loop never ends

后端 未结 1 1932
盖世英雄少女心
盖世英雄少女心 2021-01-27 13:50

So basically, I need to remove all records that don\'t have 3 as the 2nd digit in the primary key field which for example can either look like this

#39001


        
相关标签:
1条回答
  • 2021-01-27 14:34

    Try this instead:

    Sub keep3()
    
        Dim i As Integer
    
        For i = 14000 To 2 Step -1
            If Mid(Cells(i, 2), 2, 1) = "3" Then
                Rows(i).EntireRow.Delete
            End If
        Next
    
    End Sub
    

    Note that the loop is going backwards - this is because when you delete a row, the row below gets pulled up, so your loop can do strange things if you go forwards and then delete a row, as you may skip over the next row that you may have also wanted to delete. Also, I changed the IF statement as you said you want to delete rows where the 2nd character is a 3.

    0 讨论(0)
提交回复
热议问题