+ Reply to Thread
Results 1 to 6 of 6

Check user input format

Hybrid View

JSebastianRock Check user input format 10-10-2012, 09:42 AM
JSebastianRock Re: Check user input format 10-10-2012, 12:07 PM
Chippy Re: Check user input format 10-13-2012, 07:38 PM
JSebastianRock Re: Check user input format 10-15-2012, 10:11 AM
ducky_yeng Re: Check user input format 10-15-2012, 11:32 AM
JSebastianRock Re: Check user input format 10-15-2012, 11:58 AM
  1. #1
    Registered User
    Join Date
    10-10-2012
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2003
    Posts
    12

    Check user input format

    Hello!

    I'm trying to find a way to verify that user input is in a specific format (specifically "mm/dd/yyyy"). Here's what I got:

    Dim r As Long
    Dim temp1 As String
    
    r = MsgBox(prompt:="Are there any new records?", Buttons:=vbYesNo)
    
    If r = vbNo Then
        Do
            temp1 = Application.InputBox(prompt:="Enter date of last change (mm/dd/yyyy):")
        Loop While temp1 = "##/##/####" 'This is where the issue comes in
    
        With Range("A7:I7")
            .Merge
            .Font.Bold = True
            .Interior.Color = RGB(255, 255, 0)
            .Value = "NO CHANGES SINCE " & temp1
        End With
    Else
        Call WAWAFormatter
    End If
    Any help is greatly appreciated, thanks!

  2. #2
    Registered User
    Join Date
    10-10-2012
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Check user input format

    ttt

    *bump*

  3. #3
    Valued Forum Contributor
    Join Date
    05-21-2009
    Location
    Great Britain
    MS-Off Ver
    Excel 2003
    Posts
    550

    Re: Check user input format

        Dim dateInput As String
        Do
            dateInput = InputBox(prompt:="Enter date of last change (mm/dd/yyyy):")
        Loop Until dateInput Like "##/##/####"
    Post responsibly. Search for excelforum.com

  4. #4
    Registered User
    Join Date
    10-10-2012
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Check user input format

    Thank you, Chippy

    After I read your post, I realized where I went wrong. I was using the Like function at first, but I was using "Loop While" instead of "Loop Until." Of course, VBA wasn't accepting anything in that date format, but it was accepting everything that wasn't in the format. So tedious, my logic.

  5. #5
    Registered User
    Join Date
    11-09-2009
    Location
    london, england
    MS-Off Ver
    Excel 2010
    Posts
    52

    Re: Check user input format

    In addition to Chippy's suggested code. It is worth checking that the date is valid by using IsDate VBA function. This will ensure that the user has not incorrectly entered an invalid date (e.g. 29/02/2011, 31/09/2012), which can easily be done as there is no validation on the input.

  6. #6
    Registered User
    Join Date
    10-10-2012
    Location
    Virginia, USA
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Check user input format

    Thank you, ducky

    A combination of the LIKE with the added ISDATE method is exactly what I was looking for. Now, the code checks for a date in a specific format using dual nested DO LOOPS. A rather short solution, I might add.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1