Conditional Formatting a text box

Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Conditional Formatting a text box

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Location
    Yorkshire
    Posts
    212
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    I have a text box on a chart which is linked to a cell on a sheet which has a 1,2 or 3 in it. Is there any way I can set the formatting in the text box so that the background is a specific colour depending on the number in the linked cell.

    Thanks in advance

    StewartS

  2. #2
    Legend NateO's Avatar
    Join Date
    Feb 2002
    Location
    Minneapolis, Mn, USA
    Posts
    9,700
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hello Stewart. You can use a change event to set the background color, like:


    Private Sub TextBox1_Change()
    If TextBox1.Value = "" Or Not "1" Or Not "2" Or Not "3" Then _
    TextBox1.BackColor = RGB(0, 0, 0)
    If TextBox1.Value = "1" Then TextBox1.BackColor = RGB(255, 0, 0)
    If TextBox1.Value = "2" Then TextBox1.BackColor = RGB(0, 255, 0)
    If TextBox1.Value = "3" Then TextBox1.BackColor = RGB(0, 0, 255)
    End Sub


    Right click on your textbox and select view code (design mode). Paste the code in and modify the name of textbox1 to your actual name. Play with the colors as desired.

    _________________
    Cheers, Nate Oliver

    [ This Message was edited by: NateO on 2002-06-24 07:55 ]

  3. #3
    New Member
    Join Date
    Apr 2013
    Posts
    9
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Conditional Formatting a text box

      
    Hi - this worked perfectly on an Excel 2003 spreadsheet I 'm working on.

    My question is: Is there any way to edit the code above to apply the formatting to all text boxes on a worksheet rather than a specific one?

    Thanks
    Last edited by Radchek; Apr 17th, 2013 at 08:00 AM. Reason: Typo

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com