I'm trying to delete all rows where the value in Column "A" doesn't match the following field formats (1) 7 digit number, (2) Lastname, Firstname, (3) Date ... or the following values (4) INPATIENT (5) OUTPATIENT.
Line 9 keeps throwing a "Type Mismatch" error. Any ideas?
Public Sub DeleteRows()
Dim RowToTest As Long
Call setVariables '***sets wsName variable
'Code to delete unneeded rows based on cell value in Column "A"
For RowToTest = Cells(Rows.Count, 1).End(xlUp).Row To 1 Step -1
With ActiveWorkbook.Worksheets(wsName).Cells(RowToTest, 1)
If Not .Value Like "???????" Or "*[,]*" Or "*?[/]*?[/]*??" _
Or "?????[:]*" Then
If Not .Value = "INPATIENT" Or "OUTPATIENT" Then
Rows(RowToTest).EntireRow.Delete
End If
End If
End With
Next RowToTest
End Sub
your function should look like this:
Public Sub DeleteRows()
Dim RowToTest As Long
Call setVariables '***sets wsName variable
'Code to delete unneeded rows based on cell value in Column "A"
For RowToTest = Cells(Rows.Count, 1).End(xlUp).Row To 1 Step -1
With ActiveWorkbook.Worksheets(wsName).Cells(RowToTest, 1)
If Not (.Value Like "???????" Or .Value Like "*[,]*" Or .Value Like "*?[/]*?[/]*??" Or _
.Value Like "?????[:]*" Or .Value = "INPATIENT" Or .Value = "OUTPATIENT") Then
ActiveWorkbook.Worksheets(wsName).Rows(RowToTest).Delete
End If
End With
Next RowToTest
End Sub
use this:
If Not .Value Like "???????" And _
Not .Value Like "*[,]*" And _
Not .Value Like "*?[/]*?[/]*??" And _
Not .Value Like "?????[:]*" And _
.Value <> "INPATIENT" And _
.Value <> "OUTPATIENT" Then
Rows(RowToTest).EntireRow.Delete
End If
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.