My InputBox keeps looping. Even when I press cancel/ Escape

LostCause

Board Regular
Joined
Jul 13, 2006
Messages
99
Firstly, thanks for reading.

If I click the button this macro is assigned to, it loops until a value is entered. I would like to be able to press cancel or escape. Any pointers?

Thanks.


Code:
Sub MyMacro()
Dim RCP_Audit_Result6 As String
Dim Updated_Value6 As String
Dim worksheet_current_three As String
Dim yes As String
Dim no As String

Dim temp_count_three
ActiveSheet.Unprotect
temp_count_three = True
yes = "YES"
no = "NO"
worksheet_current_three = "4 RCP Results"
RCP_Audit_Result6 = Sheets(worksheet_current_three).Range("I16")
Updated_Value6 = UCase(InputBox("Please update value", , RCP_Audit_Result6))
'Sheets(worksheet_current_three).Range("G10") = Updated_Value

Do While temp_count_three = True
    If Updated_Value6 = yes Or Updated_Value6 = no Then
        temp_count_three = False
     Sheets(worksheet_current_three).Range("I16") = Updated_Value6
        'Exit Do
    Else
    Updated_Value6 = UCase(InputBox("Updated value must be YES or NO", , RCP_Audit_Result6))
    End If
Loop
ActiveSheet.Protect DrawingObjects:=True, contents:=True, Scenarios:=True
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

LostCause

Board Regular
Joined
Jul 13, 2006
Messages
99
Hmm

I tried this:

Code:
Sub MyMacro() 
Dim RCP_Audit_Result6 As String
Dim Updated_Value6 As String
Dim worksheet_current_three As String
Dim yes As String
Dim no As String

Dim temp_count_three
ActiveSheet.Unprotect
temp_count_three = True
yes = "YES"
no = "NO"
worksheet_current_three = "4 RCP Results"
RCP_Audit_Result6 = Sheets(worksheet_current_three).Range("I16")
Updated_Value6 = UCase(InputBox("Please update value", , RCP_Audit_Result6))
'Sheets(worksheet_current_three).Range("G10") = Updated_Value

Do While temp_count_three = True
    If Updated_Value6 = "" Then Exit Sub
    If Updated_Value6 = yes Or Updated_Value6 = no Then
        temp_count_three = False
     Sheets(worksheet_current_three).Range("I16") = Updated_Value6
        'Exit Do
    Else
    Updated_Value6 = UCase(InputBox("Updated value must be YES or NO", , RCP_Audit_Result6))
    End If
Loop
ActiveSheet.Protect DrawingObjects:=True, contents:=True, Scenarios:=True
End Sub

Now it let's me cancel out but sometimes it doesn't accept the correct answer. Where have I gone wrong?

Thanks!
 

LostCause

Board Regular
Joined
Jul 13, 2006
Messages
99
No problem.

Thank you for your help! I think I know where I've gone wrong... let me do some detective work and I'll post an update

Edit: I was being a complete idiot. The code works perfectly.
 

Forum statistics

Threads
1,144,611
Messages
5,725,308
Members
422,608
Latest member
bswg5882

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
Top