Results 1 to 6 of 6

Conditionally formatting ActiveX TextBox based on value

Threaded View

  1. #4
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,693

    Re: Conditionally formatting ActiveX TextBox based on value

    Hi again Jo,

    Many thanks for your feedback.

    Ok on using the Change event rather than the LostFocus event to trigger the colour change. Whenever possible I avoid using the Change event for the simple reason that the event is triggered each time any change is made to any character displayed in the TextBox rather than when all changes have been completed, but in some situations that's exactly what's needed.

    As far as your second point is concerned (it's interesting to see that you use the worksheet CodeName - good for you!! ) it seems that Excel VBA finds a statement such as "Case Is < wksThresholds.Range("B1").Value" to be "too complex", as demonstrated by the following code:

    
    
    Sub Test()
    
        Dim dValue As Double
    
        dValue = 100
    
        Select Case dValue
    
               Case Is < wksThresholds.Range("B1").Value    '   Has a value of 50
                    MsgBox "OK"
    
        End Select
    
    End Sub
    The attached workbook uses the following version of the previous routine, and it seems to work:

    
    
    Private Sub UpdateBackground(ctl As Object)
    
        Dim dLevel_1    As Double
        Dim dLevel_2    As Double
        Dim dLevel_3    As Double
        Dim dLevel_4    As Double
    
        dLevel_1 = wksThresholds.Range("B1").Value
        dLevel_2 = wksThresholds.Range("B2").Value
        dLevel_3 = wksThresholds.Range("B3").Value
        dLevel_4 = wksThresholds.Range("B4").Value
    
        Select Case ctl.Value
    
               Case Is < dLevel_1
                    ctl.BackColor = &H8080FF
    
               Case Is < dLevel_2
                    ctl.BackColor = &H80C0FF
    
               Case Is < dLevel_3
                    ctl.BackColor = &H80FF80
    
               Case Is < dLevel_4
                    ctl.BackColor = &HFF8080
    
        End Select
    
    End Sub

    Hope this helps - please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Conditionally formatting based on value changes in a row
    By green4000 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-30-2015, 04:04 PM
  2. Conditionally formatting one cell based on text in another.
    By Jsteelester in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-09-2014, 11:48 AM
  3. [SOLVED] Conditional formatting userform textbox based on textbox value
    By kidwispa in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-03-2014, 08:28 AM
  4. Multi-Worksheet ActiveX Textbox to ActiveX Textbox Concatenate
    By HVE_Skynet in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-21-2014, 02:11 PM
  5. ActiveX Textbox to ActiveX Textbox Concatentate
    By HVE_Skynet in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-17-2014, 05:22 PM
  6. Is there a way to do conditionally formatting based on a rolling date?
    By Drogo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-05-2014, 10:44 PM
  7. ActiveX Textbox Date Formatting
    By slappycat in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-23-2011, 03:44 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