Do Loop Not Working

Wilconcl51

New Member
Joined
Oct 10, 2023
Messages
26
Office Version
  1. 2016
Platform
  1. Windows
Here is my code. Error message "Loop Without Do ??"
I'm confused

Sub Tuesday_Single()

Dim rVillaNo As Range
Dim Resp As String
Dim Meal As String
Dim GFO As String
Dim Msg, Style, Title, Help, Ctxt, Response, MyString As String
Dim Check As Boolean

Do
Resp = InputBox("What is their Villa Number. Villa Number only?. ")
'Application.ScreenUpdating = False

If Len(Resp) > 0 Then
On Error Resume Next
Set rVillaNo = Range("VillaNo").Find(What:=Resp, LookAt:=xlWhole)
On Error GoTo 0
If Not rVillaNo Is Nothing Then Application.Goto Reference:=rVillaNo.Offset(, -5), Scroll:=True
End If
Meal = InputBox("Enter 1 or 2 if they are attending")
ActiveCell = Meal
ActiveCell.Offset(0, 4).Select
GFO = InputBox("Input Y or YY for Gluten Free or Enter")
ActiveCell = GFO
Check = (MsgBox("Do you want to add more ?", vbYesNo) = vbYes)
If Check = vbYes Then
Loop

Sheets("Menu").Select
End If


'Application.ScreenUpdating = True
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try This Code

VBA Code:
Sub Tuesday_Single()


    Dim rVillaNo As Range
    Dim Resp As String
    Dim Meal As String
    Dim GFO As String
    Dim Check As Boolean


    Sheets("Menu").Select ' Ensure you're on the right worksheet


    Do
        Resp = InputBox("What is their Villa Number? (Villa Number only)")
        If Resp = "" Then Exit Do ' Exit the loop if no input


        On Error Resume Next
        Set rVillaNo = Range("VillaNo").Find(What:=Resp, LookAt:=xlWhole)
        On Error GoTo 0


        If Not rVillaNo Is Nothing Then
            rVillaNo.Offset(0, 1).Value = InputBox("Enter 1 or 2 if they are attending")
            rVillaNo.Offset(0, 2).Value = InputBox("Input Y or YY for Gluten Free or Enter")
        Else
            MsgBox "Villa Number not found!", vbExclamation
        End If


        Check = MsgBox("Do you want to add more?", vbYesNo) = vbYes
    Loop While Check


    ' Application.ScreenUpdating = True ' Uncomment this line if you had previously disabled screen updating


End Sub
 
Upvote 0
Solution
Try This Code

VBA Code:
Sub Tuesday_Single()


    Dim rVillaNo As Range
    Dim Resp As String
    Dim Meal As String
    Dim GFO As String
    Dim Check As Boolean


    Sheets("Menu").Select ' Ensure you're on the right worksheet


    Do
        Resp = InputBox("What is their Villa Number? (Villa Number only)")
        If Resp = "" Then Exit Do ' Exit the loop if no input


        On Error Resume Next
        Set rVillaNo = Range("VillaNo").Find(What:=Resp, LookAt:=xlWhole)
        On Error GoTo 0


        If Not rVillaNo Is Nothing Then
            rVillaNo.Offset(0, 1).Value = InputBox("Enter 1 or 2 if they are attending")
            rVillaNo.Offset(0, 2).Value = InputBox("Input Y or YY for Gluten Free or Enter")
        Else
            MsgBox "Villa Number not found!", vbExclamation
        End If


        Check = MsgBox("Do you want to add more?", vbYesNo) = vbYes
    Loop While Check


    ' Application.ScreenUpdating = True ' Uncomment this line if you had previously disabled screen updating


End Sub
Thank you so much
Works perfectly
 
Upvote 0
@Wilconcl51
In future, please mark the actual post that answered your question. I have change the 'Mark as solution' from post 4 to post 2

Also, I have mentioned before (see here) to use code tags when posting vba code in the forum. Please do so in future.
 
Upvote 0
@Wilconcl51
In future, please mark the actual post that answered your question. I have change the 'Mark as solution' from post 4 to post 2

Also, I have mentioned before (see here) to use code tags when posting vba code in the forum. Please do so in future.
Thank you.

Now I'm totally confused as I thought I had.
Apologies. I will have to look elsewhere.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

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