+ Reply to Thread
Results 1 to 6 of 6

Conditionally formatting ActiveX TextBox based on value

  1. #1
    Registered User
    Join Date
    06-26-2014
    Location
    Christchurch, New Zealand
    MS-Off Ver
    2010
    Posts
    43

    Smile Conditionally formatting ActiveX TextBox based on value

    Hi

    I have a spreadsheet with many ActiveX Textboxes which values are linked to a cell on another sheet. What I'm trying to do is change the back colour of the Textboxes based on their value to create a Traffic Light Report ie when the value changes so to does the back colour.

    The reason I'm trying to do it this way is so that I can move the Textboxes and change their shape to create a map as such. The map often changes, so much easier to move and reshape a Textbox rather than cells which is what we currently do. Also having issues with the current cell model as many cells have been merged to try and create a map that is visually accurate.

    To start with I've tried just playing with one Textbox using the text box change event and a couple of other methods but haven't had any luck. If I could get that to work I was then going to try and figure out how to apply to all textboxes at once.

    Any help/suggestions would be much appreciated!

    Thanks

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

    Re: Conditionally formatting ActiveX TextBox based on value

    Hi there,

    Take a look at the attached workbook and see if it does the sort of thing you need.

    It uses the following code:

    Please Login or Register  to view this content.

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

    Regards,

    Greg M
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    06-26-2014
    Location
    Christchurch, New Zealand
    MS-Off Ver
    2010
    Posts
    43

    Re: Conditionally formatting ActiveX TextBox based on value

    Hi Greg

    Thanks so much for that, I've had a play with the attachment you sent. I linked the text box to a cell on the same sheet but when I change the cell the textbox colour doesn't change. However when I change the value within the text box and click elsewhere it does work. I've changed the function from 'Lost Focus' to 'Change' and this seems to work a treat.

    I've tried to take it a step further and replace 50,100,150 etc with a value from another sheet (Sheet1.Range("B20").Value) but this seems to cause an issue and the colour no longer changes. Any idea where I'm going wrong?

    Thanks
    Jo

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

    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:

    Please Login or Register  to view this content.
    The attached workbook uses the following version of the previous routine, and it seems to work:

    Please Login or Register  to view this content.

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

    Regards,

    Greg M
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    06-26-2014
    Location
    Christchurch, New Zealand
    MS-Off Ver
    2010
    Posts
    43

    Re: Conditionally formatting ActiveX TextBox based on value

    Hi Greg

    Thanks so much, this is working well! Thanks for explaining about the Lost Focus too, I make this stuff up as I go along so always great to have someone who knows what they're doing explain these details to me so I can store them away for future use!

    Thanks again,
    Jo

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

    Re: Conditionally formatting ActiveX TextBox based on value

    Hi again,

    Thanks for your feedback.

    You're welcome - glad I was able to help.

    Regards,

    Greg M

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