Results 1 to 7 of 7

How to make 3 < 22 ?

Threaded View

  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'.

        
    ' if new value is larger than ref value, show red background
    
        If New.Value = "" Or Ref.Value = "" Then
            New.BackColor = &H80000005  'white
        Else
             If New.Value <= Ref.Value Then
                New.BackColor = &HC0FFC0    'green
             Else
                New.BackColor = &HC0C0FF    'red
             End If
        End If
    
    ' (The .Value Type of each textbox is "Variant/String")
    I tried using "CDec" but that didn't seem to work. What do I need to do?

        
    New = CDec(New)
    Ref = CDec(Ref)
    
    'OR, also tried:
    
    New.Value = CDec(New.Value)
    Ref.Value = CDec(Ref.Value)
    Thank you much, in advance!
    Last edited by Sqwid; 11-26-2019 at 01:26 PM. Reason: Edited for typos/clarification

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