Results 1 to 3 of 3

Conditional Formatting a text box

This is a discussion on Conditional Formatting a text box within the Excel Questions forums, part of the Question Forums category; I have a text box on a chart which is linked to a cell on a sheet which has a ...

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Location
    Yorkshire
    Posts
    162

    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,702

    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

    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 07:00 AM. Reason: Typo

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