Deleting specific rows

GraceTilly

New Member
Joined
Dec 16, 2024
Messages
3
Office Version
  1. 2021
Platform
  1. Windows
I have a face recognition device that biometrically checks people in and out of work and at the end of each month I download the data onto an excel spreadsheet.
My issue is that during the course of one month if the facial recognition does not immediately recognise the face it returns the word Undefined in column F, instead of the words, "Check in" or "Check out". What I am hoping to do is highlight the sheet and delete all rows that have the word Undefined in column F. Is this possible? To do each sheet (twenty employees) individually row by row would be hugely time consuming.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
paste into module , then run: DeleteBadRows

Code:
Public Sub DeleteBadRows()
Dim i As Integer
Dim iRows As Integer
On Error Resume Next

Range("A1").Select
iRows = ActiveSheet.UsedRange.Rows.Count
Cells(iRows, 1).Select

While ActiveCell.Row > 1
   GoSub check2Delete
   ActiveCell.Offset(-1, 0).Select     'prev row
Wend
GoSub check2Delete
Exit Sub

check2Delete:
  If InStr(ActiveCell.Offset(0, 5).Value, "Undefined") > 0 Then
  Rows(ActiveCell.Row).Delete
  End If
Return
End Sub
 
Upvote 0
Another option:
VBA Code:
Sub DeleteRows()
  On Error Resume Next
  Columns("F").Replace "Undefined", "#N/A", xlWhole, , False
  Columns("F").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
  On Error GoTo 0
End Sub
 
Upvote 0
Solution
paste into module , then run: DeleteBadRows

Code:
Public Sub DeleteBadRows()
Dim i As Integer
Dim iRows As Integer
On Error Resume Next

Range("A1").Select
iRows = ActiveSheet.UsedRange.Rows.Count
Cells(iRows, 1).Select

While ActiveCell.Row > 1
   GoSub check2Delete
   ActiveCell.Offset(-1, 0).Select     'prev row
Wend
GoSub check2Delete
Exit Sub

check2Delete:
  If InStr(ActiveCell.Offset(0, 5).Value, "Undefined") > 0 Then
  Rows(ActiveCell.Row).Delete
  End If
Return
End Sub
Thank you so much, works like a charm and will save me hours.
 
Upvote 0
Another option:
VBA Code:
Sub DeleteRows()
  On Error Resume Next
  Columns("F").Replace "Undefined", "#N/A", xlWhole, , False
  Columns("F").SpecialCells(xlConstants, xlErrors).EntireRow.Delete
  On Error GoTo 0
End Sub
Thank you so much you and this website have been a life saver.
 
Upvote 0
I would highly recommend the second code over the first.
Selecting cells in loops will unnecessarily slow your code down, and is usually unnecessary.
Loops in general are slow as it is, and they are not even needed here (as shown in the second code).
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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