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
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
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
 
Upvote 0
Thanks, that fixed that part. Could you also tell me what's wrong with the case action statements?
 
Upvote 0
Actually, never mind. I just needed to place interior before .color.

Thanks for the help.
 
Upvote 0

Forum statistics

Threads
1,214,999
Messages
6,122,645
Members
449,093
Latest member
Ahmad123098

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top