PDA

View Full Version : Sleeper: VBA using Loop



lela0643
12-02-2022, 02:45 AM
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

macropod
12-02-2022, 04:03 AM
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.

lela0643
12-02-2022, 05:33 AM
Ofc your're right, but I have absolutely no clue

Fluff
12-02-2022, 05:42 AM
Cross-posted https://www.mrexcel.com/board/threads/vba-using-loop.1223673/
Which is where the code came from.

macropod
12-02-2022, 12:52 PM
lela0643: Kindly read VBA Express' policy on Cross-Posting in Rule 3: How to Use Our Site (vbaexpress.com) (http://www.vbaexpress.com/forum/faq.php?faq=new_faq_item#faq_new_faq_item3)

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) (http://www.vbaexpress.com/forum/faq.php?faq=psting_faq_item#faq_hom_faq_item)

Thread closed.

Aussiebear
12-02-2022, 01:34 PM
@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.