+ Reply to Thread
Results 1 to 5 of 5

Changing colour of text box when data is added.

  1. #1
    Registered User
    Join Date
    10-28-2010
    Location
    durham
    MS-Off Ver
    Excel 2003
    Posts
    4

    Changing colour of text box when data is added.

    I have a userform with around 100 text boxes, these are populated from a worksheet. however if there is no data on the sheets then the text box back colour is yellow to highlight it. If data is then added, I want the colour to change to white. I can do this individually using the textbox(number)_change backcolour but is there a way to code for all text boxes change instead of 100 different short codes

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Changing colour of text box when data is added.

    Try this...

    Add a new userform and 2 textboxes. Paste the following in the userform code module:
    Please Login or Register  to view this content.
    Add a new CLASS module. Paste the following to the class:
    Please Login or Register  to view this content.
    Leave all names as the default, the Class should be named Class1. Hopefully you do not have any other classes (Doubtful ) but it's easy enough to change.

    Try running that (the userform, not your complete project) and see if you can understand what's going on... The key to this is the declaration using WITHEVENTS in the Class and the array of classes in the userform.

    After running once, add another textbox or 2. No coding changes will be needed for the new textboxes to respond to changes. (Hopefully!)
    Last edited by cytop; 02-02-2014 at 08:26 AM. Reason: Clarification

  3. #3
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Changing colour of text box when data is added.

    There are two ways to do this.

    The simplest is to use a subroutine

    Untested Code:
    Please Login or Register  to view this content.
    You will need 100 of the textbox change sub routines.

    But these can be created in excel using another macro and then cut and pasted into visual basic.

    Please Login or Register  to view this content.

    ___________________________________________________________________________________________________________________________________________________________

    The Second is to create a new cllass of object.

    This shows you how:

    http://www.ozgrid.com/forum/showthread.php?t=141695
    Last edited by mehmetcik; 02-02-2014 at 08:57 AM.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,438

    Re: Changing colour of text box when data is added.

    Use a class to handle the change event for numerous textboxes.
    Attached Files Attached Files
    Cheers
    Andy
    www.andypope.info

  5. #5
    Registered User
    Join Date
    10-28-2010
    Location
    durham
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Changing colour of text box when data is added.

    Thanks for the prompt replies, I have gone with cytop's reply which is working a treat. I am trying to pick the code apart to understand what is happening. thanks again

+ 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. Changing colour on changing a Data Validation List added with VBA
    By e4excel in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-16-2011, 08:15 AM
  2. changing all text boxes of one fill colour to another colour
    By was0696 in forum Word Formatting & General
    Replies: 3
    Last Post: 02-18-2010, 05:57 AM
  3. Excel 2007 : Changing text colour within a strings
    By Pigmy in forum Excel General
    Replies: 4
    Last Post: 10-21-2009, 07:41 AM
  4. Changing the text colour on a button
    By Robin Quinnell in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-09-2007, 09:21 AM
  5. Replies: 3
    Last Post: 04-23-2005, 06:06 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