+ Reply to Thread
Results 1 to 4 of 4

Numeric Values in a textbox

  1. #1
    Registered User
    Join Date
    10-23-2006
    Posts
    84

    Numeric Values in a textbox

    I have a problem witth a section of code that loads in a monitary value.

    If Cells(Cr, 5).Value <> "" Then
    Cells(Cr, 6).Value = Round(0.1489361 * Cells(Cr, 5).Value, 2)
    Cells(Cr, 7).Value = Round(Cells(Cr, 5).Value - Cells(Cr, 6).Value, 2)

    If alphanumeric values are entered into the textbox that put the code into cell Cr,5 the program crashes.

    I know it's because of the Round() function but I need to use it otherwise the returned value is to 10 decimal places.

    How can I get the textbox to accept numeric values only please?

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525
    here's a code I have for one of my textboxes

    Please Login or Register  to view this content.

  3. #3
    Forum Expert Carim's Avatar
    Join Date
    04-07-2006
    Posts
    4,070
    Hi,

    Instead of Round() function, take a look at Format()or Text() functions

    HTH
    Carim

  4. #4
    Registered User
    Join Date
    10-23-2006
    Posts
    84
    Thanks changed code to:

    If IsNumeric(Cells(Cr, 5).Value) = True Then
    Cells(Cr, 6).Value = Round(0.1489361 * Cells(Cr, 5).Value, 2)
    Cells(Cr, 7).Value = Round(Cells(Cr, 5).Value - Cells(Cr, 6).Value, 2)
    Else: Rows(Cr) = ""
    End If

    Seems to work a treat.

+ 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