Select Case Problems

ouadad

Board Regular
Joined
Jun 19, 2005
Messages
213
I thought this was an easy code to write, but apparently I'm wrong in a number of places. On one worksheet (Labelling) I'm reading a string and if it matched the case it outputs a colour in exactly the same cell pointer on another worksheet (Colour Chart).


Sub ColourChart1()
Dim irow As Integer, icol As Integer, System As String
For irow = 10 To 148
For icol = 2 To 255
System = Worksheets("Labelling").Cells(irow, icol)
Select Case System
Case "E" Or "e"
Worksheets("Colour Chart").Cells(irow, icol).Color = RGB(255, 0, 0)
Case "S" Or s
Worksheets("Colour Chart").Cells(irow, icol).Color = RGB(204, 255, 204)
Case "H" Or "h"
Worksheets("Colour Chart").Cells(irow, icol).Color = RGB(51, 153, 102)
Case "R" Or "r"
Worksheets("Colour Chart").Cells(irow, icol).Color = RGB(255, 204, 153)
Case "F" Or "f"
Worksheets("Colour Chart").Cells(irow, icol).Color = RGB(255, 255, 0)
Case "C" Or "c"
Worksheets("Colour Chart").Cells(irow, icol).Color = RGB(255, 153, 0)
Case "D" Or "d"
Worksheets("Colour Chart").Cells(irow, icol).Color = RGB(255, 0, 255)
Case Else
End Select
Next icol
Next irow

End Sub
 

Some videos you may like

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

Code:
Sub ColourChart1()
Dim irow As Integer, icol As Integer, System As String
For irow = 10 To 148
    For icol = 2 To 255
        System = Worksheets("Labelling").Cells(irow, icol)
        Select Case UCase(System)
        Case "E"
            Worksheets("Colour Chart").Cells(irow, icol).Color = RGB(255, 0, 0)
        Case "S"
            Worksheets("Colour Chart").Cells(irow, icol).Color = RGB(204, 255, 204)
        Case "H"
            Worksheets("Colour Chart").Cells(irow, icol).Color = RGB(51, 153, 102)
        Case "R"
            Worksheets("Colour Chart").Cells(irow, icol).Color = RGB(255, 204, 153)
        Case "F"
            Worksheets("Colour Chart").Cells(irow, icol).Color = RGB(255, 255, 0)
        Case "C"
            Worksheets("Colour Chart").Cells(irow, icol).Color = RGB(255, 153, 0)
        Case "D"
            Worksheets("Colour Chart").Cells(irow, icol).Color = RGB(255, 0, 255)
        End Select
    Next icol
Next irow
End Sub
 

ouadad

Board Regular
Joined
Jun 19, 2005
Messages
213
Thanks, that fixed that part. Could you also tell me what's wrong with the case action statements?
 

ouadad

Board Regular
Joined
Jun 19, 2005
Messages
213
Actually, never mind. I just needed to place interior before .color.

Thanks for the help.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,083
Messages
5,526,753
Members
409,717
Latest member
Oscarsalone

This Week's Hot Topics

Top