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

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
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,213,560
Messages
6,114,309
Members
448,564
Latest member
ED38

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