Using If Else to return vlaue other than 0 when an inputbox is canceled

jordanl

New Member
Joined
Jan 25, 2013
Messages
7
Hi,
I have an inputbox that sets a public variable and uses if...else to change that value if one has already been set. What I'd like to do is when the user runs the sub when a value has already been set and clicks cancel rather than entering a new value, the value stays as it is rather than gets switch to 0 (or false, or whatever canceling an inputbox does). Here's the sub as it is now:
Code:
Public HldWrkBk As String
Sub HoldWrkBk()
    If HldWrkBk = "" Then
        HldWrkBk = InputBox("Enter Holding Workbook")
    Else
        HldWrkBk = InputBox(HldWrkBk, "Enter New Holding Workbook")
    End If
End Sub

Thanks!!!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
I think you'll need another variable to store the result from the input box.
 
Upvote 0
I think I figured out a way to do what I need:
Code:
Sub HoldWrkBk()
    If HldWrkBk = "" Then
        HldWrkBk = InputBox("Enter a Holding Workbook")
    Else
        HldWrkBk = InputBox("Enter a new Holding Workbook or click okay to continue with the current workbook", , HldWrkBk)
    End If
End Sub
This way, it uses the current variable as the default text so if you click okay, it just reenters it.
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,011
Members
452,374
Latest member
keccles

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