简体   繁体   中英

Excel VBA InputBox value is not a date

I have a user input box where you type in a string, annoyingly this string looks like a date 00/00/0000 and excel reformats it as such. When the value can't be a date ex. 18/19/4561 (month can't be 18 or 19) it displays it correctly. But whenever it can be seen as a possible date it switches things around.

I've tried setting the value as a string rather than nothing but excel still changes it when putting it in the page.

When I try manually inputting it in the cell or equal the values from a manually entered cell it works fine.

But whenever I get it from the inputbox it messes with it. Even when I hard code the string to a variable ( x = "05/06/4564" ) it switches things around.

How do I force excel to leave the string as is?

Prefix the value with a single apostrophe and Excel will interpret it as a string.

Eg '18/19/4561

Also, have you tried setting the cell format to Text

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM