Select Case Isn't Working Correctly

BrandynBlaze

New Member
Joined
Sep 20, 2012
Messages
29
Hello, I'm very new to this still and can't figure out why my select case loop isn't working. I just want it to format my headers if they match specific text values two of the cases are shown below for "FEA" and "SUN". When I run the code it only changes the cells to one color, not two different colors, and the cell that comes after the header is what is changing. Ultimately I need to change the colors for 8-10 different headers.

Code:
For i = 0 To LstCol
    
    Header = ActiveCell.Value
    MsgBox Header
    
    Select Case Header
    
        Case FEA:
                
        With Selection.Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .ThemeColor = xlThemeColorAccent2
            .TintAndShade = 0.4
            .PatternTintAndShade = 0
        End With
        
        Case SUN:


        With Selection.Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .ThemeColor = xlThemeColorAccent2
            .TintAndShade = 0.599993896298105
            .PatternTintAndShade = 0
        End With
    
    End Select
    
    ActiveCell.Offset(0, 1).Select




Next i
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
If you are checking for the strings 'FEA' and 'SUN' then use double quotes.
Code:
For i = 0 To LstCol
    
    Header = ActiveCell.Value
    MsgBox Header
    
    Select Case Header
    
        Case "FEA"
                
        With Selection.Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .ThemeColor = xlThemeColorAccent2
            .TintAndShade = 0.4
            .PatternTintAndShade = 0
        End With
        
        Case "SUN"


        With Selection.Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .ThemeColor = xlThemeColorAccent2
            .TintAndShade = 0.599993896298105
            .PatternTintAndShade = 0
        End With
    
    End Select
    
    ActiveCell.Offset(0, 1).Select

Next i
 
Upvote 0
Code:
Select Case Header
    
        Case "FEA":
                
        For j = 1 To LstRow
        
        ActiveCell = Range(Cells(j, i))
        
           If ActiveCell.IsEmpty = True then


                With Selection.Interior


                    .Pattern = xlSolid
                    .PatternColorIndex = xlAutomatic
                    .ThemeColor = xlThemeColorAccent2
                    .TintAndShade = 0.7
                    .PatternTintAndShade = 0


                End With


            End If


        Next j

Okay so that fixed that part of the issue but now I can't get my code to check all the cells under that header so that it adds color to any cells with no data. Any suggestions?
 
Upvote 0
Try this.
Code:
Select Case Header
    
        Case "FEA":
                
        For j = 1 To LstRow
                
           If Cells(j, i).Value = "" then
                With Cells(j, i).Value.Interior
                    .Pattern = xlSolid
                    .PatternColorIndex = xlAutomatic
                    .ThemeColor = xlThemeColorAccent2
                    .TintAndShade = 0.7
                    .PatternTintAndShade = 0
                End With
            End If

        Next j
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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