+ Reply to Thread
Results 1 to 2 of 2

Verifying user input from InputBox

Hybrid View

nbuk Verifying user input from... 06-25-2010, 11:24 AM
royUK Re: Verifying user input from... 06-25-2010, 01:22 PM
  1. #1
    Registered User
    Join Date
    06-25-2010
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2003
    Posts
    34

    Verifying user input from InputBox

    I have a macro which asks the user to input several values and then I need to test and see if they are valid. Here is the current code that I have

    Dim CutDate As Date
    Dim CutDay, CutMunth, CutYear, CutHour, CutMinute As Integer
    
    CutMonth:
        CutMonth = Application.InputBox("Please enter the month of the DSS cut (1 to 12)")
        If CutMonth < 1 Or CutMonth > 12 Then GoTo CutMonth
        
    CutDay:
        CutDay = Application.InputBox("Please enter the day of the DSS cut (1 to 31)")
        If CutDay < 1 Or CutDay > 31 Then GoTo CutDay
        
    CutYear:
        CutYear = Application.InputBox("Please enter the year of the DSS cut (4 digits)")
        If CutYear <= 1000 Or CutYear >= 9999 Then GoTo CutYear
        
    CutHour:
        CutHour = Application.InputBox("Please enter the hour of the DSS cut (0 to 23)")
        If CutHour < 0 Or CutHour > 23 Then GoTo CutHour
        
    CutMinute:
        CutMinute = Application.InputBox("Please enter the minute of the DSS cut (0 to 59)")
        If CutMinute < 0 Or CutMinute > 59 Then GoTo CutMinute
        
    CutDate = DateSerial(CutYear, CutMonth, CutDay) + TimeSerial(CutHour, CutMinute, 0)
    The issue I am having is that if the user enters a decimal it will be accepted. Also I want to be able to cancel the input, i.e. if the user presses cancel the input box will disappear.

    Can anyone please offer me any suggestions to improve the code?

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Verifying user input from InputBox

    Why not create a UserForm it would be much more professional looking
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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