-2

READ CAREFULLY THE QUESTION PLEASE, IT MENTIONS EXCEL VBA. NOT EXCEL

I was given the task of fixing a date input on a VBA form. A textbox should have the user enter the date as MM/DD/YYYY.

I am required to use an input mask, not allowed to do something as validating date after or using a calendar. So far I was able to use the 2 methods mentioned (forcing the format after using ISDATE).

However, it has now been made clear it has to be a mask so keys are filtered on entry, with the mask being visible when entering the date: __/__/____

Where you see underscore, he should only be able to enter numbers and the / are always at those positions

Is there a way to do this? I can only find a tutorial for the mask in Access VBA.

Community
  • 1
  • 1
Cher
  • 2,789
  • 10
  • 37
  • 64
  • 1
    Please provide examples of the data you're working with, what you're trying to do with it, and the *related* code you have so far, showing which part is causing your *specific* problem. (More info at "[mcve]" and well as [these tips](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/).) – ashleedawg Apr 08 '18 at 06:09
  • You didn't search very hard for the answer to your homework assignment ... – ashleedawg Apr 08 '18 at 06:28
  • I'm not sure how to specify more the question, a date mask is a date mask – Cher Apr 09 '18 at 16:49
  • see my first comment, above. – ashleedawg Apr 09 '18 at 16:57

2 Answers2

0

I Googled "Excel input mask" and the 2nd result was: Using an Input Mask Microsoft Excel written by Allen Wyatt...

Using an Input Mask

...You may wonder if there is a way to set up an input mask that will add the colon automatically. The good news is yes, there is. The bad news is no, there isn't. Sound confusing? Let me explain...

You can set up a custom format that will display your time in any format you want. For instance, you could use the following steps:

  1. Select the cells you want to use for time input.
  2. Choose Format from the Cells menu. Excel displays the Format Cells dialog box.
  3. Make sure the Number tab is displayed.
    image: The Number tab of the Format Cells dialog box.
  4. In the Category list, choose Custom.
  5. Replace whatever is in the Type box with #":"00.
  6. Click on OK.

You can now enter your times using just digits. The problem (and this is the bad news) is that the cell doesn't really contain a time. If you enter 230 (for 2:30), it doesn't contain 2:30 as a time—it contains two hundred and thirty. Thus, you can't use the contents of the cell directly in time calculations.

To overcome this, you can use another column to show the entered digits converted into a time. All you need to do is use a formula to do the conversions. For instance, if the time you entered was in cell A3, you could use the following formula in a different cell to do the conversion:

=(INT(A3/100)/24)+((A3 - (INT(A3/100)*100))/1440)

Format the cell that contains the above formula so it displays one of the various time formats, and you are all set.

(Full article and more at the source.)

ashleedawg
  • 20,365
  • 9
  • 72
  • 105
  • yes and you found something for excel not excel vba which is mentionned in the question. I found this one too – Cher Apr 09 '18 at 16:38
  • I would guess you are also the one who changed the tag in my questions from excel-vba to excel explaining why I get answer for excel cells now – Cher Apr 09 '18 at 16:40
  • @Cher it appears I inadvertently did remove the [tag:Excel-VBA] tag - I had intended to add [tag:Excel] and [tag:VBA] in addition to the many grammatical and formatting changes I made to your otherwise difficult-to-understand question. Clarity and details (such as spelling/formatting) are important. You're welcome to `rollback` to **undo my changes in [Revision #3 here](https://stackoverflow.com/posts/49714545/revisions)** if think that'll help. Also **you have not explained *why* you required VBA instead of a much simpler, built-in solution.** More information is helpful. See [mcve] & [ask]. – ashleedawg Apr 09 '18 at 17:04
  • I do start the question by saying it's a textbox in a vba form... if this isn't clear not sure what I can add... so since I use a form I do need vba. Not sure it can be more clear. Are you familiar with vba form? – Cher Apr 09 '18 at 17:45
  • I'm not trying to be rude, and I do understand question should be clear, but with the situation as presented, to anybody who code in excel vba, I can't see what I could add to be more clear – Cher Apr 09 '18 at 17:46
0

This post may help you...

Formatting MM/DD/YYYY dates in textbox in VBA

Harun24hr
  • 30,391
  • 4
  • 21
  • 36
  • thx but this doesn't work on mine version (french version) and user also wants a mask he doesn't want to hear about anything else – Cher Apr 09 '18 at 16:55