+ Reply to Thread
Results 1 to 5 of 5

macro to change font color with drop down list

Hybrid View

  1. #1
    Registered User
    Join Date
    09-11-2012
    Location
    Rockville, MD
    MS-Off Ver
    Excel 2003
    Posts
    47

    macro to change font color with drop down list

    I have a listbox from which to choose font color for editing, linked to another cell. This code points to that linked cell to find the color choice and then specifies the font should be that color. It only works sometimes and I cannot figure out why. I put in the msgBox to track the variable. The message box comes up, but the variable value does not. So clearly the variable is not being set properly. Any ideas?

    Private Sub Worksheet_Change(ByVal Target As Range)
    Const WS_RANGE As String = "A1:z300"
    If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
    Dim colorchoice As String
    Dim color As Integer
    'Application.ScreenUpdating = False
    Sheets(4).Activate
    colorchoice = Range("b1").Value
    If colorchoice = RED Then
    color = 3
    ElseIf colorchoice = BLUE Then
    color = 5
    ElseIf colorchoice = "GREEN" Then
    color = 4
    Else: color = 17
    End If
    Sheets(1).Activate
    'Application.ScreenUpdating = True
    With Target
    .Font.ColorIndex = color
    MsgBox "color is" & colorchoice
    End With
    End If
    End Sub

  2. #2
    Forum Contributor
    Join Date
    10-08-2010
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    386

    Re: macro to change font color with drop down list

    you don't have quotes around red or blue for starters.

  3. #3
    Registered User
    Join Date
    09-11-2012
    Location
    Rockville, MD
    MS-Off Ver
    Excel 2003
    Posts
    47

    Re: macro to change font color with drop down list

    Yes, that is true. I was experimenting with that part of the code. It doesn't work with or without the quotes.

  4. #4
    Forum Contributor
    Join Date
    10-08-2010
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    386

    Re: macro to change font color with drop down list

    I just tested it, it is working for me. maybe post your work book?

  5. #5
    Registered User
    Join Date
    09-11-2012
    Location
    Rockville, MD
    MS-Off Ver
    Excel 2003
    Posts
    47

    Re: macro to change font color with drop down list

    Thanks for trying to help with this. I don't know why it worked for you, but not me. I changed the code that specifies the location of the "colorchoice" variable. It works perfectly now. Thanks again.

    Private Sub Worksheet_Change(ByVal Target As Range)
    Const WS_RANGE As String = "A1:z300"
    If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
    Dim colorchoice As String
    Dim color As Integer
    colorchoice = Worksheets(4).Range("b1").Value
    If colorchoice = "RED" Then
    color = 3
    ElseIf colorchoice = "BLUE" Then
    color = 5
    ElseIf colorchoice = "GREEN" Then
    color = 4
    Else: color = 17
    End If
    With Target
    .Font.ColorIndex = color
    End With
    End If
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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