+ Reply to Thread
Results 1 to 13 of 13

Validating a cell contains an integer

Hybrid View

  1. #1
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Validating a cell contains an integer

    Quote Originally Posted by cultofcargo View Post
    I have written some code to validate that a user input field contains a whole number;
    Perhaps, OP wants to do like
    Dim msg As String
    If IsNumeric(Range("Quantity1")) Then
        If Range("Quantity1") Mod 1 <> 0 Then
             msg ="Quantity must be a whole number, to rectify this please enter a whole number in the quantity field.", vbCritical, "Operator Response Required"
        End if
    Else
        msg = "Only Numbers allowed"
    End if
    If Len(msg) then
        msgbox msg
        Range("Quantity1").ClearContents
        Range("Quantity1").Select
    End if

  2. #2
    Registered User
    Join Date
    10-24-2014
    Location
    Gloucestershire, England
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Validating a cell contains an integer

    Quote Originally Posted by skywriter View Post
    Is "Quantity1" a cell on a spreadsheet?
    VarType is supposed to be used with a variable.
    You would have to create a variable, let's say x.
    x = Range("Quantity1").Value
    If VarType(x)......
    Yes Quantity1 is a cell

    x = Range("Quantity1").Value
    If VarType(x) = vbInteger Then
    Else
    MsgBox "Quantity must be a whole number, to rectify this please enter a whole number in the quantity field.", vbCritical, "Operator Response Required"
    Range("Quantity1").ClearContents
    Range("Quantity1").Select
    Exit Sub
    End If


    With this written i am still getting the error message no matter what is in the cell.

    And storing x (quantity1) using Dim will return messages based on what i store it as in the Dim statement (string, boolean, integer)

+ 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] Validating user name in cell
    By momoknz in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-11-2013, 11:25 PM
  2. Replies: 2
    Last Post: 06-30-2013, 03:30 PM
  3. Validating a cell value
    By tonyromero in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-28-2013, 04:50 AM
  4. Replies: 3
    Last Post: 10-27-2011, 05:20 PM
  5. Validating a cell
    By m.cain in forum Excel General
    Replies: 5
    Last Post: 07-07-2011, 03:51 PM
  6. Count the number of occurrences of an integer withing a larger integer
    By nnktran in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-26-2010, 01:04 PM
  7. Validating a Cell
    By leelu_uma in forum Excel General
    Replies: 2
    Last Post: 11-05-2008, 06:47 AM
  8. [SOLVED] Validating certain cell
    By Kasey in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 08-17-2006, 10:50 AM

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