+ Reply to Thread
Results 1 to 13 of 13

Use an if statement on a Text Box

  1. #1
    Registered User
    Join Date
    07-15-2014
    Location
    Birmingham
    MS-Off Ver
    2013
    Posts
    18

    Use an if statement on a Text Box

    Hi All,

    I am making a user entry form where they have to enter some figures. I would like them to only enter a number between 2.4 and 6. How can I do this?

    My code at the moment is this:
    Please Login or Register  to view this content.

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Use an if statement on a Text Box

    put your code on the exit event not the change. and add into the incorrect path me.txtHeight=0, ditch the height number, as its a converted to a string anyway,

    Please Login or Register  to view this content.
    Hope this helps

    Sometimes its best to start at the beginning and learn VBA & Excel.

    Please dont ask me to do your work for you, I learnt from Reading books, Recording, F1 and Google and like having all of this knowledge in my head for the next time i wish to do it, or wish to tweak it.
    Available for remote consultancy work PM me

  3. #3
    Registered User
    Join Date
    07-15-2014
    Location
    Birmingham
    MS-Off Ver
    2013
    Posts
    18

    Re: Use an if statement on a Text Box

    Sorry Nathan, you know me, but can you lay it out like code?

    This is my code now:
    Please Login or Register  to view this content.

  4. #4
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Use an if statement on a Text Box

    I have, you just need to replace the calculation with your calculation and the warning message with yours.

  5. #5
    Registered User
    Join Date
    07-15-2014
    Location
    Birmingham
    MS-Off Ver
    2013
    Posts
    18

    Re: Use an if statement on a Text Box

    Thanks for that Nathan. However now I am receiving an error - http://gyazo.com/eae2deb94365810d4ebb5144c78efee2

  6. #6
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Use an if statement on a Text Box

    Can you post the whole code behind the form

  7. #7
    Registered User
    Join Date
    07-15-2014
    Location
    Birmingham
    MS-Off Ver
    2013
    Posts
    18

    Re: Use an if statement on a Text Box

    Yes sure - I have now somewhat fixed the error - instead of converting to string I have converted to Double (DBL).

    When an incorrect number is entered, an error is shown (great!) when the number is deleted, it throws and error again (when nothing is entered)

  8. #8
    Registered User
    Join Date
    07-15-2014
    Location
    Birmingham
    MS-Off Ver
    2013
    Posts
    18

    Re: Use an if statement on a Text Box

    Please Login or Register  to view this content.
    Here is the entire code.

  9. #9
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Use an if statement on a Text Box

    Ok, i said to get rid of that. "ditch the height number, as its a converted to a string anyway"

  10. #10
    Registered User
    Join Date
    07-15-2014
    Location
    Birmingham
    MS-Off Ver
    2013
    Posts
    18

    Re: Use an if statement on a Text Box

    When that is deleted, it now looks like this:
    Please Login or Register  to view this content.
    But now it says any number entered is incorrect, and it will not update the total cost text box.

  11. #11
    Registered User
    Join Date
    07-15-2014
    Location
    Birmingham
    MS-Off Ver
    2013
    Posts
    18

    Re: Use an if statement on a Text Box

    Thank you Nathan, error now fixed. This is the code I am now using (this may be sloppy, but it works)

    Please Login or Register  to view this content.

  12. #12
    Valued Forum Contributor
    Join Date
    09-21-2011
    Location
    Birmingham UK
    MS-Off Ver
    Excel 2003/7/10
    Posts
    2,188

    Re: Use an if statement on a Text Box

    You are doing your if wrong, you only have one outcome, but are still using else,your calc should be before else otherwise it will still calculate after the messagebox has been dispalyed, so do the logic in the IF like i said


    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    07-15-2014
    Location
    Birmingham
    MS-Off Ver
    2013
    Posts
    18

    Re: Use an if statement on a Text Box

    I presume you mean
    Please Login or Register  to view this content.
    instead of 'isnumerc' ?

+ 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. [SOLVED] adding text in front of potentially existing text (in 1 cell) with IF/THEN statement
    By Marijke in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-10-2014, 04:20 AM
  2. Replies: 6
    Last Post: 08-28-2013, 10:50 PM
  3. [SOLVED] If Or statement to check cell text and delete entire row if text is found
    By VBA FTW in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-08-2013, 11:46 AM
  4. IF statement for text
    By hermithead in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-10-2010, 10:34 PM

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