+ Reply to Thread
Results 1 to 4 of 4

If Statement and Message Box error

  1. #1
    Registered User
    Join Date
    11-05-2015
    Location
    Australia
    MS-Off Ver
    2013
    Posts
    6

    If Statement and Message Box error

    Hi,

    I'm trying to use an if statement for my userform that I'm building like so and want it show like so:

    txtempid:

    If textempid < 1000 Then textempid = ""
    MsgBox "Please enter valid Emp ID", vbOKOnly
    Else: textempid.Value
    End If

    Can someone please help me correct it?

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,633

    Re: If Statement and Message Box error

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    Perhaps
    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527

    Re: If Statement and Message Box error

    Hi jwong03,

    Welcome to the forum!!

    You could also use a listbox that is populated with the employee id's (either from a sheet or directly via code) so that user only has to select the relevant id. This eliminates the need to check the data entry made by the user.

    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  4. #4
    Registered User
    Join Date
    11-05-2015
    Location
    Australia
    MS-Off Ver
    2013
    Posts
    6

    Re: If Statement and Message Box error

    Thank you!!

    I managed to get it working with this instead:

    If txtempid.Value <= 1000 Then
    MsgBox ("Please enter valid Emp ID")
    Else:
    Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Offset(1) = txtempid.Value
    Sheets("Sheet1").Cells(Rows.Count, 2).End(xlUp).Offset(1) = txtfirstname.Value

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Error message if there is a certain statement in a cell
    By Engineeronamission in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-08-2014, 07:02 AM
  2. An error message on open - a totally blank VBA message box
    By Mr_Tigas in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-05-2013, 11:29 AM
  3. Error message in if statement - reg
    By mvel_sky in forum Excel General
    Replies: 2
    Last Post: 04-25-2012, 08:49 AM
  4. Using a Boolean function within an If statement: Argument not optional error message
    By elfsprin in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-16-2011, 04:12 PM
  5. replace VBA run-time error message with custom message
    By BEEJAY in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 07-14-2006, 11:05 AM
  6. Why does this statement give an error message?
    By George Furnell in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-18-2006, 10:50 AM

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