Results 1 to 6 of 6

Thread: Sleeper: VBA using Loop

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Sleeper: VBA using Loop

    Exercise: Find a student
    Open the workbook "Résultats examen.xlsx". In the first spreadsheet (Results) you have a list of students.
    1) Build a VBA macro that asks the user with a dialog box, the name of the student to find. This macro will browse the list and select the cell corresponding to the name of the student.
    2) The macro informs the user, with a second dialog box, if the student has been received.
    3) If all the list has been explored and the name has not been found, the macro displays the message “student not found in the list” and select the first empty cell below the names list.

    Can anyone help me? So far I have this but it does not work

    Sub Search()
        Dim fnd As Variant
        Dim FoundCell As Range
        Dim rng     As Range
        Do
            fnd = InputBox("Enter Student Name To search", "Enter Name")
            If StrPtr(fnd) = 0 Then Exit Sub
        Loop Until Len(fnd) > 0
    
            Set FoundCell = Range("A:A").Find(fnd, , xlValues, xlPart, , , False, , False)
            If Not FoundCell Is Nothing Then
                FoundCell.Select
                MsgBox fnd & Chr(10) & "was found in the list", 48, "Found"
                Exit Sub
            End If
    
        MsgBox fnd & Chr(10) & "student not found in the list", 48, "Not Found"
        Set rng = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
        rng.Select
    End Sub
    Attached Files Attached Files
    Last edited by Aussiebear; 12-02-2022 at 05:36 AM. Reason: Added code tags to supplied code

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •