VBA - Msgbox inside a Loop

0 votes

I've got the userform attached. Every time I click the "Proceed!" button, I have it verify that the weight of all batches combined is greater than the weight that was initially assigned in the Product Details box;

If I say yes, it prompts me to move on or not; if I say no, I want the userform to allow me to adjust the quantities once more.

I've typed the code below, however whenever I select "No," the message box repeatedly appears:

Private Sub CommandButton1_Click()     'Proceed! Button
Dim answer As Integer

q = Val(Left(Label2.Caption, 5))       'Weight in Product Details --> 15.12 tons 

Total = BatchTotal1 + BatchTotal2 + BatchTotal3 + BatchTotal4 + BatchTotal5  'Publicly dimmed previously

Again:

If Total > q Then
    answer = MsgBox("Batches total weight is more than you assigned first, Do you want to proceed?", vbQuestion + vbYesNo)
    If answer = vbYes Then
        GoTo Continue
    Else
        GoTo Again
    End If
End If

Continue:

'Another code
Mar 19 in Others by narikkadan
• 60,820 points
47 views

1 answer to this question.

0 votes

 Try this:

Private Sub CommandButton1_Click()     'Proceed! Button

    Dim answer As Long

    q = Val(Left(Label2.Caption, 5))       'Weight in Product Details --> 15.12 tons 

    Total = BatchTotal1 + BatchTotal2 + BatchTotal3 + BatchTotal4 + BatchTotal5  'Publicly dimmed previously
    If Total > q Then
        answer = MsgBox("Batches total weight is more than you assigned first, Do you want to proceed?", vbQuestion + vbYesNo)
        If answer <> vbYes Then
            Exit Sub
        Else
    End If

    ' Another code

End Sub
answered Mar 19 by Kithuzzz
• 35,300 points

Related Questions In Others

0 votes
1 answer

Excel VBA: Open Hyperlinks in a loop and copy paste download link in a sheet

Refer this tutorial for your solution: https://evermap.com/Tutorial_AB ...READ MORE

answered Dec 25, 2022 in Others by narikkadan
• 60,820 points
311 views
0 votes
1 answer

How to increment the Range of a For Each loop - Excel VBA

Your formula seems to sum 1 single ...READ MORE

answered Jan 7 in Others by narikkadan
• 60,820 points
324 views
0 votes
1 answer

VBA Loop to select then copy a range of cells based on value in column B

Try this: Sub Macro2() Dim ...READ MORE

answered Mar 23 in Others by narikkadan
• 60,820 points
28 views
0 votes
1 answer

Excel VBA userform paste text in expanded format (not just to one cell)

It should work if you simply supply ...READ MORE

answered Jan 21 in Others by narikkadan
• 60,820 points
82 views
0 votes
1 answer

Excel VBA Scheduled message pop up box reminder

What exactly does W11 contain? In Excel, ...READ MORE

answered Feb 3 in Others by narikkadan
• 60,820 points
89 views
0 votes
1 answer

EXCEL Userform - Creating multiple Labels and Textboxes with specific names

Please, test the next scenario: Insert a class ...READ MORE

answered Feb 9 in Others by narikkadan
• 60,820 points
124 views
0 votes
1 answer

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
577 views
0 votes
1 answer

VBA - Dynamic Variable Name in a Loop

Set the array values with: Dim i as ...READ MORE

answered Mar 19 in Others by Kithuzzz
• 35,300 points
54 views
0 votes
1 answer

Excel VBA- How to loop through specific sheets in a workbook and format the same ranges in each sheet

Range(...) instructs VBA to always use the ...READ MORE

answered Mar 21 in Others by Kithuzzz
• 35,300 points
39 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP