+ Reply to Thread
Results 1 to 7 of 7

Spin Button linked to text box needs to only accept numeric input

  1. #1
    Forum Contributor
    Join Date
    12-19-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    191

    Spin Button linked to text box needs to only accept numeric input

    Hi All,

    I have a form with a text box that can either be typed into or controlled with a spin button, I have the following code for the spin button to align the two items:

    Please Login or Register  to view this content.
    This works fine for numbers (you can type a number and then increase or decrease it with the buttons or overwrite a number reached with the buttons) but if you accidentally hit any other key on the keyboard or delete the number in the text box I get an error and am thrown back into the VBA editor. Obviously I need this to be a little more robust for the end users so would appreciate any help in getting the code to ignore text input and allow the number in the text box to be deleted without breaking the form.

    Thanks

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

    Re: Spin Button linked to text box needs to only accept numeric input

    ISNUMERIC will check that its a numeric value
    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
    Forum Contributor
    Join Date
    12-19-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    191

    Re: Spin Button linked to text box needs to only accept numeric input

    Hi Nathansav,

    How would I incorporate that into the code? I'm a complete VBA n00b!

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

    Re: Spin Button linked to text box needs to only accept numeric input

    I would personally do it in a way where i have the previous value taken to a variable

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    12-19-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    191

    Re: Spin Button linked to text box needs to only accept numeric input

    Thanks nathansav!

    I played around a bit and used the following:

    Please Login or Register  to view this content.
    The only issue is the error box comes up twice if a letter is typed, i'll have to figure that out separately though.

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

    Re: Spin Button linked to text box needs to only accept numeric input

    may be beacuse you will always have nothin in prevvalue, you need to put the check for me.rejectedbox.text<>"" in the change and also set the prev value to be me.rejectedbox.text, like mine prevvalue = Me.TextBox1.Text

  7. #7
    Forum Contributor
    Join Date
    12-19-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    191

    Re: Spin Button linked to text box needs to only accept numeric input

    Aah, gotcha. Thanks

+ 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. Macro based on Spin Button Linked cell value
    By turist in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-20-2013, 11:57 AM
  2. Spin Button variable linked cell
    By Ozzmatron in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-18-2013, 11:29 PM
  3. [SOLVED] Macro based on Spin Button Linked cell value
    By turist in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-15-2013, 04:07 PM
  4. Accept button to allow input
    By navajo_23 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-16-2011, 01:05 PM
  5. How to make the spin button's linked cell vary
    By Irascivel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-31-2009, 06:39 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