+ Reply to Thread
Results 1 to 4 of 4

Checking if value is negative

  1. #1
    Registered User
    Join Date
    09-08-2014
    Location
    -
    MS-Off Ver
    -
    Posts
    68

    Checking if value is negative

    Greetings,
    In my form, I have textboxes which cannot have negative values - with than in mind, I have code such as

    Please Login or Register  to view this content.
    That works fine when the value is negative.
    The issue is, there is an option to leave the box blank and it will calculate a default value based on previously entered parameters.
    So, when the user leaves the box blank, it comes up with type mismatch when performing the above check.
    I tried

    Please Login or Register  to view this content.
    Any suggestions?

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Checking if value is negative

    Test if the textbox is not blank before trying to convert the text to a number. Maybe something like...

    Please Login or Register  to view this content.
    Additionally, this avoids a potential error if the user entered text instead of a number.
    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 09-11-2014 at 04:13 AM.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    09-08-2014
    Location
    -
    MS-Off Ver
    -
    Posts
    68

    Re: Checking if value is negative

    I was just thinking that that would work. Just made some silly errors applying it with all the 019203910 surround ElseIf's I had going...
    Thanks! It works.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,972

    Re: Checking if value is negative

    Separate the tests. Check for blank first ... if it is, take the appropriate action. If it isn't, then check for the negative value.

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ 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] SUMIF positive and negative numbers - take double a negative number?
    By Zordrail in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-16-2014, 08:34 AM
  2. Replies: 1
    Last Post: 04-26-2012, 12:48 AM
  3. Checking for Negative Numbers
    By andyb400 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-03-2009, 07:07 PM
  4. Replies: 1
    Last Post: 11-20-2008, 01:52 AM
  5. [SOLVED] Checking if a number entered is positive or negative
    By Karen27 in forum Excel General
    Replies: 2
    Last Post: 05-13-2005, 01:06 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