+ Reply to Thread
Results 1 to 16 of 16

Prevent users from entering alphabet!

  1. #1
    Registered User
    Join Date
    10-19-2008
    Location
    India
    Posts
    7

    Prevent users from entering alphabet!

    Hi,

    I have a doubt, how could i prevent the users from entering a alphabet in a cell ,like people do in java script.

    example : there is a field called Quantity, since the quantity field should contain only numbers, i have done this by using data validation (i.e) the user can enter alphabets and it shows the error only after the user enters it.
    but i dont want anything to be entered except numbers.

    Please help!!!

    Thanks

  2. #2
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    Hi se7en_hills,

    As far as i know you cant do that but you could make it so that it will take it back out as soon as the user changes the value in a cell eg.

    if i put the letter A in cell E10 i could then use a piece of code to take it out once i have entered it. would that help at all
    There are only 10 types of people in the world:
    Those who understand binary, and those who don't!

  3. #3
    Registered User
    Join Date
    06-12-2008
    Location
    Newbury
    MS-Off Ver
    Office 365 ProPlus
    Posts
    92
    You could do this with the onkey method

    If you put the following in the worksheet change event:

    Please Login or Register  to view this content.
    This isn't 100% as they can still double click on a cell or start with a number and then put alphabetic characters in but it stops them from just starting to type text into a cell.

  4. #4
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    wouldnt that stop them from using them anywhere in that workbook or worksheet

  5. #5
    Registered User
    Join Date
    06-12-2008
    Location
    Newbury
    MS-Off Ver
    Office 365 ProPlus
    Posts
    92
    It would in its current form but you could restrict it to a particular range easily enough. Probably also want to tag on a isnumeric(target.value) to make sure the final output is a number as well.

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531
    This would seem to be a x-post ...

    http://www.mrexcel.com/forum/showthread.php?t=349064

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    se7en-hills- please do not cross post without adding a link

    Why not use Data validation.
    Hope that helps.

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

    Free DataBaseForm example

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531
    royuk, I believe (interpret) OP to be using validation already -- I think perhaps there is just confusion as to whether or not an invalid entry is "committed".

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    I can't see what the problem is, if the user enters a non numeric number, data validation will allow the user to retry, or delete the entry if Cancel is selected

  10. #10
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531
    Yes, exactly.

  11. #11
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Maybe he has the error alert style set to Warning or Info, rather than Stop, allowing the use of alpha characters after overriding the warning.

  12. #12
    Registered User
    Join Date
    10-17-2008
    Location
    Norcross, GA
    MS-Off Ver
    MS Excel 2007
    Posts
    35
    Hi I dont know if this will help but i search online before for my own project but this code applies to textbox... maybe you can change it a little? if it doesn't help im sorry!

    Please Login or Register  to view this content.
    Last edited by okriskao; 10-24-2008 at 12:04 PM. Reason: code tag

  13. #13
    Registered User
    Join Date
    10-19-2008
    Location
    India
    Posts
    7
    Hi,
    Thanks for ur replies. i'm sorry for the cross post. i'm new and i dont know whether it comes under the rules. can't i post it in more than one forums???

    @DonkeyOte royUK - I have used Data Validation, what u said was exactly correct i.e. the user can't enter alphabets and error message will be shown. But this doesn't restrict the user from copying and pasting.
    Thats y i went for asking like , it shouln't allow the alpha itself.

    expecting a solution here

    Thanks

  14. #14
    Registered User
    Join Date
    10-19-2008
    Location
    India
    Posts
    7
    @okriskao

    Thanks for the code. Appreciate it. But my requirements is only to use cells...

  15. #15
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531
    see a similar thread which in turn has a link to John Walkenbach's solution:

    http://www.excelforum.com/excel-misc...alidation.html

    this will require VBA to handle the value change though

  16. #16
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Or maybe this change event macro

    Right click sheet tab and select view code. Paste this in.
    Please Login or Register  to view this content.
    Then add this to a normal module
    Please Login or Register  to view this content.
    Link explains more about VBScript with Regular Expressions
    http://msdn.microsoft.com/en-us/library/ms974570.aspx

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

+ 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