+ Reply to Thread
Results 1 to 7 of 7

How to make 3 < 22 ?

  1. #1
    Registered User
    Join Date
    11-26-2019
    Location
    Connecticut
    MS-Off Ver
    2016
    Posts
    3

    Question How to make 3 < 22 ?

    Hello,

    I have a userform set up that compares the values of two textboxes ('New' and 'Ref'), which occurs every time either textbox is changed. When 'New' > 'Ref', 'New' should change to a red background.

    It is currently telling me that 3 > 22.3 and 5 > 49.15, etc. because when 'New' has 5 or 5.00 and 'Ref' has 49.15, it returns 'New' as red.

    When 'Ref' is 0.49 or 4.91, this code works. But when 'Ref' has double digit whole numbers like 49.1, it gets confused and compares the starting '4' in '49' with the single digit '5'.

    Please Login or Register  to view this content.
    I tried using "CDec" but that didn't seem to work. What do I need to do?

    Please Login or Register  to view this content.
    Thank you much, in advance!
    Last edited by Sqwid; 11-26-2019 at 01:26 PM. Reason: Edited for typos/clarification

  2. #2
    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
    44,447

    Re: How to make 3 < 22 ?

    Use CDbl instead of CDec.
    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


  3. #3
    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
    44,447

    Re: How to make 3 < 22 ?

    And convert them both.

  4. #4
    Registered User
    Join Date
    11-26-2019
    Location
    Connecticut
    MS-Off Ver
    2016
    Posts
    3

    Re: How to make 3 < 22 ?

    Thanks for your quick response!

    I tried this before the code (with and without the ".value") but it didn't seem to do the trick. In the Locals menu the .Value was still "Variant/String" after passing through this code.

    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: How to make 3 < 22 ?

    1. Assign text boxes values ​​to variables
    2. Examine the decimal sign of a number (in text boxes) and depending on it use the 'CDbl' or 'Val' function
    3. You can recognize the decimal sign of numbers in the system with "Application.International (xlDecimalSeparator)"

  6. #6
    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
    44,447

    Re: How to make 3 < 22 ?

    Post an example. See the yellow banner at the top of every screen.

  7. #7
    Registered User
    Join Date
    11-26-2019
    Location
    Connecticut
    MS-Off Ver
    2016
    Posts
    3

    Red face Re: How to make 3 < 22 ?

    Got it! This likely isn't the sleekest way of doing it, but this is what's worked for me.
    I did what porucha suggested and just converted the texbox values to their own variables dim'd as double, and I did this in a separate function.


    (SA_TB stands for Surface Area Text Box)

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    I made a function and replaced "SA" with "Val" so I can do the same for Mass and Volume.
    Last edited by Sqwid; 11-26-2019 at 04:43 PM. Reason: added clarification

+ 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. Replies: 1
    Last Post: 10-03-2019, 04:35 PM
  2. Replies: 8
    Last Post: 11-08-2013, 07:46 AM
  3. trying to make a button on summary page to make new working sheet
    By dbzisme in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 04-07-2013, 05:41 PM
  4. Replies: 0
    Last Post: 03-08-2013, 06:34 AM
  5. Replies: 7
    Last Post: 12-27-2012, 10:53 PM
  6. make macros usable! make instructions in plain english !!!!
    By Brainless_in_Boston in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 03-02-2006, 11:30 AM
  7. Replies: 0
    Last Post: 01-12-2005, 10: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