Using an InputBox where the default is a field

AntMac

Board Regular
Joined
Dec 1, 2009
Messages
146
What I would like to do is have the default of an input box be the value of one of my cells. If the cell is blank, then I would like the default value of the input box to be blank. If it's populated than it's value is the default value. It seems that I get an error message when I store the value of the cell as a variable and put that as the default value of the inputbox. Is there any way to do this other than to check for if the value is blank and do an if then statement with different default values?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Here is a example:

Makes the default value in the InputBox the same as the value in Range("A1")

Code:
Sub My_Input()
Dim ans As String
ans = InputBox("Enter Value", "My Input Box", Range("A1").Value)
End Sub
 
Upvote 0
Ok, this was a user error lol I had my then and else options flipflopped. I switched those and it worked as desired. Sorry about that. But thank you for helping me look deeper into it to find the problem.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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