+ Reply to Thread
Results 1 to 6 of 6

Color fonts in column G Based on Contents in Column E

Hybrid View

  1. #1
    Registered User
    Join Date
    01-21-2009
    Location
    Nanning, China
    MS-Off Ver
    Excel 2003
    Posts
    12

    Color fonts in column G Based on Contents in Column E

    Hello
    I have created an Excel spreadsheet teachers schedule for a small school with 8 teachers. I have assigned a number to each teacher (1 - 8) so that a number typed in a cell in Column E will cause a teachers name to appear in a cell in Column G. The ranges are E3:E20 and G3:G20. I hope to find a Macro that will display each teachers name in a different color. Thank you everyone for your assistance.
    Last edited by ChinaReg; 01-22-2009 at 10:23 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    See the code in this earlier post, you should be able to adapt it for what you need.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606
    You could use the worksheet change event. Right-click worksheet tab, view code and paste this in. It colours the cell, but be altered to font, and vary the numbers to change actual colours.
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Intersect(Target, Range("E3:E20")) Is Nothing Then Exit Sub
    
    Select Case Target.Value
        Case 1 To 8: Target.Offset(, 2).Interior.ColorIndex = Target.Value + 2
        Case Else: Target.Offset(, 2).Interior.ColorIndex = 0
    End Select
    
    End Sub
    Last edited by StephenR; 01-21-2009 at 08:47 AM.

  4. #4
    Registered User
    Join Date
    01-21-2009
    Location
    Nanning, China
    MS-Off Ver
    Excel 2003
    Posts
    12
    Thank you StephenR and RoyUk for responding so quickly. Stephen your answer is the best fit for my situation. I have a followup question if I may. Is it possible to extend the code to other columns on the same page? It works great in column E and G,but can the code be expanded to column I and K, M and O and so on? Many Thanks

  5. #5
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606
    I'm not sure what "and so on" might entail, but this should work up to col O:
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim rng As Range
    
    If Intersect(Target, Range("E3:E20")) Is Nothing Then Exit Sub
    
    Set rng = Union(Target.Offset(, 2), Target.Offset(, 4), Target.Offset(, 6), Target.Offset(, 8), Target.Offset(, 10))
    
    Select Case Target.Value
        Case 1 To 8: rng.Interior.ColorIndex = Target.Value + 2
        Case Else: rng.Interior.ColorIndex = 0
    End Select
    
    End Sub

  6. #6
    Registered User
    Join Date
    01-21-2009
    Location
    Nanning, China
    MS-Off Ver
    Excel 2003
    Posts
    12
    Thanks again Stephen, you understood exactly what I needed and it works perfectly. This one is solved!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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