I have the following code that deletes all rows containing a certain string provided through an input box.
If crit = selRange.Cells(i, 1).Value Then
To This:
If crit <> selRange.Cells(i, 1).Value Then
It didn’t work - probably because I don’t understand exactly what is happening with the next three rows of code. Any help would be appreciated.
I would like to change the code from equals (=) to does not equal (<>) as follows:Sub DeleteRows()
'Delete rows by selecting the range and entering the criteria.
'Range should be a single column. How to capture and enforce?
Dim i As Integer
Dim j As Integer
Dim selRange As Range
Dim crit As String 'Use Integer or Variable if not String.
Set selRange = Selection
'Cycle through rows in selRange and delete entire row when crit
'equals the current value.
j = 0
For i = selRange.Rows.Count To 1 Step -1
If crit = selRange.Cells(i, 1).Value Then
selRange.Cells(i, 1).EntireRow.Delete
j = j + 1
End If
Next i
If crit = selRange.Cells(i, 1).Value Then
To This:
If crit <> selRange.Cells(i, 1).Value Then
It didn’t work - probably because I don’t understand exactly what is happening with the next three rows of code. Any help would be appreciated.