+ Reply to Thread
Results 1 to 9 of 9

vba macros to force user to input numeric values for numeric values with hyphen

  1. #1
    Forum Contributor
    Join Date
    09-13-2013
    Location
    Saudi Arabia
    MS-Off Ver
    2010, 2013
    Posts
    192

    vba macros to force user to input numeric values for numeric values with hyphen

    Hello,

    I am looking for a VBA Macros to force user to enter numbers of numbers with hyphen in range F3:I3.

    For example: 1298 or 1298-2 or 1298-4

    If a user did not enter properly message will be displayed for wrong entry.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: vba macros to force user to input numeric values for numeric values with hyphen

    Try this in the Sheet module:

    Please Login or Register  to view this content.

    Directions for running the routine(s) just supplied

    Copy the code to the clipboard

    Press ALT + F11 to open the Visual Basic Editor.

    Save your Workbook As Macro-Enabled

    Click on the appropriate sheet

    Type "Option Explicit" then paste the code under it

    And, you should be ready to go

    Last edited by xladept; 09-27-2013 at 05:12 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: vba macros to force user to input numeric values for numeric values with hyphen

    @ xladept,

    Makes perfectly sense to me.

    I would, however add:

    Please Login or Register  to view this content.
    Regards
    Last edited by Winon; 09-27-2013 at 05:35 PM. Reason: Syntax
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: vba macros to force user to input numeric values for numeric values with hyphen

    FYI -

    When working with Change or SelectionChange events, you need to be careful not to create a cascade event failure. This happens when changing a cell's value in the event. It will call the event again. This can happen ad inifinitum causing a stack overflow error. for example...

    A better and more robust approach would be...
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: vba macros to force user to input numeric values for numeric values with hyphen

    @ Leith Ross,

    Oops, I missed that very important bit.

    I shall blame it on me, being way pass my bedtime.

    Thank you, for coming to the rescue, Leith!

    Signing off for now, to prevent any further blunders.

    Regards

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: vba macros to force user to input numeric values for numeric values with hyphen

    @Leith - Can you explain why the placing of the disable events..enable events is poor in my code??

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: vba macros to force user to input numeric values for numeric values with hyphen

    Hello xladept,

    What you did in your code will work. The end user can often outsmart the code writer by generating an unexpected error. It has happened to me in the past and the user later contacts me that Excel is not working. Often times, a little prevention will make the user swear by you instead of at you.

  8. #8
    Forum Contributor
    Join Date
    09-13-2013
    Location
    Saudi Arabia
    MS-Off Ver
    2010, 2013
    Posts
    192

    Re: vba macros to force user to input numeric values for numeric values with hyphen

    Thanks to all of your xladept, Winon & Leith Ross.

    Mr. Leith Ross it works for me as i want. Thank you all of your for your spending time and help for me. i really appreciate.

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: vba macros to force user to input numeric values for numeric values with hyphen

    You're welcome!

+ 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] UDF to Vlookup multiple delimited values (numeric/non-numeric) and sum found values
    By Geert Rottiers in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-21-2013, 09:30 AM
  2. [SOLVED] Help find MAX value in one column when numeric & alph-numeric values are present
    By KevinAB in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 05-01-2013, 11:29 AM
  3. Replies: 2
    Last Post: 06-04-2012, 12:22 PM
  4. Extracting Numeric Values from an Alpha/Numeric String
    By Delkath in forum Excel General
    Replies: 5
    Last Post: 10-27-2010, 02:36 PM
  5. input numeric values only on textbox
    By stoey in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-05-2009, 02:24 PM

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