Code to accept upper & lower case values

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Morning,

Just for my learning curve.

Below is a code that works fine as long as say TUESDAY is entered into a cell.

If a user types Tuesday, tuesday etc etc has no affect.

How is this overcome so the code doesnt just allow UPPERCASE but either UPPER / LOWER case.

Thanks very much.


Rich (BB code):
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim My_Range As Range
    
    Dim LastRow As Long
    
    Set My_Range = Worksheets("COLOR CELLS").Range("A1:Z50")
    
    For Each cell In My_Range
    
    If cell.Value Like "MONDAY" Then
        cell.Interior.ColorIndex = 3
        
    ElseIf cell.Value Like "TUESDAY" Then
        cell.Interior.ColorIndex = 4
        
    ElseIf cell.Value Like "WEDNESDAY" Then
        cell.Interior.ColorIndex = 22
        
    ElseIf cell.Value Like "THURSDAY" Then
        cell.Interior.ColorIndex = 6
        
    ElseIf cell.Value Like "FRIDAY" Then
        cell.Interior.ColorIndex = 7
        
    ElseIf cell.Value Like "SATURDAY" Then
        cell.Interior.ColorIndex = 8
        
    ElseIf cell.Value Like "SUNDAY" Then
        cell.Interior.ColorIndex = 46
        
    Else
        cell.Interior.ColorIndex = xlNone
        
    End If
    
    Next
    
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
You could use:

Code:
    Select case UCase$(cell.Value)
       Case "MONDAY"
        cell.Interior.ColorIndex = 3
        
    Case "TUESDAY"
        cell.Interior.ColorIndex = 4
        
    Case "WEDNESDAY"
        cell.Interior.ColorIndex = 22
        
    Case "THURSDAY"
        cell.Interior.ColorIndex = 6
        
    Case "FRIDAY"
        cell.Interior.ColorIndex = 7
        
    Case "SATURDAY"
        cell.Interior.ColorIndex = 8
        
    Case "SUNDAY" 
        cell.Interior.ColorIndex = 46
        
    Case Else
        cell.Interior.ColorIndex = xlNone
        
    End Select
 
Upvote 0
Solution

Forum statistics

Threads
1,214,891
Messages
6,122,105
Members
449,066
Latest member
Andyg666

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