Hi all,

  • Thread starter Francois via OfficeKB.com
  • Start date
F

Francois via OfficeKB.com

Private Sub Worksheet_Change(ByVal Target As Range)


On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range("C1:C50")) Is Nothing Then
With Target
Select Case UCase(.Value)
Case "A": .Interior.ColorIndex = 3
Case "B": .Interior.ColorIndex = 4
Case "C": .Interior.ColorIndex = 5
Case "D": .Interior.ColorIndex = 6
Case "E": .Interior.ColorIndex = 7
Case "F": .Interior.ColorIndex = 8
Case "G": .Interior.ColorIndex = 9
Case "H": .Interior.ColorIndex = 10
Case "I": .Interior.ColorIndex = 11
Case "J": .Interior.ColorIndex = 12
Case "K": .Interior.ColorIndex = 13


' Selection.Font.ColorIndex = 3

End Select
End With
End If


ws_exit:
Application.EnableEvents = True
End Sub
 
R

Rick Rothstein \(MVP - VB\)

If you come back to this thread, you might find it interesting that this
part of your code...

Select Case UCase(.Value)
Case "A": .Interior.ColorIndex = 3
Case "B": .Interior.ColorIndex = 4
Case "C": .Interior.ColorIndex = 5
Case "D": .Interior.ColorIndex = 6
Case "E": .Interior.ColorIndex = 7
Case "F": .Interior.ColorIndex = 8
Case "G": .Interior.ColorIndex = 9
Case "H": .Interior.ColorIndex = 10
Case "I": .Interior.ColorIndex = 11
Case "J": .Interior.ColorIndex = 12
Case "K": .Interior.ColorIndex = 13

' Selection.Font.ColorIndex = 3

End Select

can be replaced by this shorter piece of code...

If .Value Like "[A-Ka-k]" Then
.Interior.ColorIndex = Asc(UCase(.Value)) - 62
End If

I wasn't sure what the commented out statement was for; but if you meant it
to go in a Case Else block, then you would duplicate that by adding an Else
section to the If-Then block to handle it.

Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top