How to delete row based on cell value ?
Use this code:
Dim i As Long i = 1 Do While i <= ThisWorkbook.ActiveSheet.Range("A1").CurrentRegion.Rows.Count If InStr(1, ThisWorkbook.ActiveSheet.Cells(i, 1).Text, "-", vbTextCompare) > 0 Then ThisWorkbook.ActiveSheet.Cells(i, 1).EntireRow.Delete Else i = i + 1 End If Loop End Sub
User can loop through at the cells in our range and also use the InStr function and to check if a cell contains a string, in our case; a hyphen.
Sub DeleteRowsWithHyphen() Dim rng As Range For Each rng In Range("A2:A10") 'Range of values to loop through If InStr(1, rng.Value, "-") > 0 Then 'InStr returns an integer of the position, if above 0 - It contains the string rng.Delete End If Next rng End Sub