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 to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,031
Messages
5,856,936
Members
431,841
Latest member
jaybeem

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
Top