Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with looping an If statement 1

Status
Not open for further replies.

richand1

Programmer
Feb 4, 2004
88
GB
Can anybody suggest where I should go with this please? I would like this if statement to loop until the user clicks "Yes":

Code:
Sub Period_Year_Input()

Dim Answer1 As String
Dim MyNote1 As String

FinancialYear1 = InputBox("What financial year is this report for? (YYYY)", "Financial Year Input")
Period1 = InputBox("What period is this report for? (1-12)", "Period Input")

MyNote1 = "Are you sure that this report is for P" & Period1 & ", " & FinancialYear1 & "?"
    
Answer1 = MsgBox(MyNote1, vbQuestion + vbYesNo, "Richosoft Excel")

If Answer1 = vbNo Then

[green]'Instead of "Exit Sub" here, I'd like the routine to loop back to the start so the user can correct any mistakes
[/green]
Exit Sub

Else

End If
[green]
'Rest of code here
[/green]
End Sub

Does this make sense? I'd like the user to be able to hit no and have the code loop until they are sure the inputs are correct. Currently, the routine is linked to a manual button the user has to press to kick off the code but, of course, the routine just ends when they haven't got it right so they then have to press the button again if they answer "No".

Many thanks all.

Rich
 
Hi,
Code:
Do
  Answer1 = MsgBox(MyNote1, vbQuestion + vbYesNo, "Richosoft Excel")

  If Answer1 = vbYes Then

     Exit Do

  End If
Loop


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Skip, as ever very helpful and, of course, spot on.

Thanks very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top