Consulting

Results 1 to 6 of 6

Thread: Sleeper: VBA using Loop

  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

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Quote Originally Posted by lela0643 View Post
    Can anyone help me?
    Yes, but we're not going to do it for you. After all, the whole purpose of such exercises is to have you show what you've learnt and to push you to extend your current abilities.

    Please attach a workbook containing the code you've developed so far and tells us where it's not doing what you expect.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    Ofc your're right, but I have absolutely no clue
    Last edited by lela0643; 12-02-2022 at 08:32 AM. Reason: Added code tags to supplied code

  4. #4
    Cross-posted https://www.mrexcel.com/board/thread...-loop.1223673/
    Which is where the code came from.

  5. #5
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    lela0643: Kindly read VBA Express' policy on Cross-Posting in Rule 3: How to Use Our Site (vbaexpress.com)

    As for the project itself, it's evident you haven't invested any effort of your own. In effect, you're asking people to help you cheat. Kindly also read VBA Express' policy on Homework: Special Posting Rules (vbaexpress.com)

    Thread closed.
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  6. #6
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,054
    Location
    @lela0643. Your behaviour here has been quite deceptive hasn't it? It's not just the fact that you cross posted the issue and failed to indicate that you've do so, but that you've deliberately edited your posts to hide your intent rather than for correcting the post content.

    Initially your first post did not include any code at all, and after Macropod asking for you to post a workbook, you edited your initial post to include the code provided by Jimmypop ( a member at Mr Excel.com) and then also included the code in your second post. At this point you still failed to indicate the cross posting. Fluff mentioned your cross posting late last night ( Australian time) and in response you came back and edited your second post very early this morning by removing the code from your second post. I strongly suspect that you would have tried to further edit your initial post but couldn't do so because of the time limit.

    At this point of time, I can't help the feeling that you're not a good fit to this forum.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

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
  •