Excel VB Userform TextBox - How do I enter 1/2" without it changing to a date

Excel_Temp

New Member
Joined
Oct 4, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I have created a search on a Userform TextBox where the user enters data. The data in the cells that I am searching over contains lots of imperial sized items (7/16", 1/2" ...) Each time I enter the number after the '/' it changes to a date. Any suggestions would be helpful.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Are you entering data into the TextBox and it changes to a date? Or entering data in a cell and it changes to a date?

If TextBox:
Anything typed into a textbox will be interpreted as text. The only way for this to happen is if your code changes it. Do you have any subs for events for the TextBox? Please show your UserForm code.

If cells:
Are you doing calculations on the sizes or just using them as text? If you just need them as text, then format the column as "Text" and it will take whatever you type in without trying to convert it. If you need to do calculations, then you need format the column as "Fraction" and when you type 7/16 it will display 7/16 and hold 0.4375 as the underlying value. But then you can't search on "7/16". Your search code would have to be changed to look at the .Text property of the cells instead of doing a .Find or whatever you are doing. Please show your UserForm code.
 
Upvote 0
I've sorted this out. I had the following line of code:

Me.TextBox1 = Format(StrConv(Me.TextBox1, vbLowerCase))

This Converted it to a date format. Any ideas Why?
 
Upvote 0
Because you are using Format without specifying a format, so it will convert it to whatever it thinks it looks like. If you type 1/2 into a cell Excel will think it's a date and that is what's happening here.
 
Upvote 0

Forum statistics

Threads
1,215,108
Messages
6,123,132
Members
449,098
Latest member
Doanvanhieu

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