Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 90251

Find and delete row with multiple criteria

$
0
0

I have a list of student records listed with surname in column B and first name in column C. On the user form is a search function which fills in the student name into the value surname.value and firstname.value, i then want a command button to find that person on the record list and delete the entire row. I had this coding working with message boxes, i then changed the message box to delete row and now it does not work.

Private Sub CommandButton1_Click()

Dim ws As Worksheet
Set ws = Worksheets("-student records no CVI")


     Dim rngFound As Range
    Dim strFirst As String
    Dim strID As String
    Dim strDay As String

    strID = Surname.Value
    strDay = Firstname.Value

    Set rngFound = Columns("B").Find(strID, Cells(Rows.Count, "B"), xlValues, xlWhole)
    If Not rngFound Is Nothing Then
        strFirst = rngFound.Address
        Do
            If LCase(Cells(rngFound.row, "C").Text) = LCase(strDay) Then
                'Found a match
                ws.Rows(rngFound.row).EntireRow.Delete

            End If
            Set rngFound = Columns("B").Find(strID, rngFound, xlValues, xlWhole)
        Loop While rngFound.Address <> strFirst
    End If

    Set rngFound = Nothing

End Sub

Viewing all articles
Browse latest Browse all 90251


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>